/* * Inline assembly snippet * Polprog 2018 * 3 clause BSD */ #include int main(){ int h; std::cout << "Enter h: "; std::cin >> h; bool a; asm volatile (" \ cmp $10, %[h] \n\ mov $1, %[a] \n\ jg 1f \n\ mov $0, %[a] \n\ 1: \n\ ": [a] "=r" (a) : [h] "r" (h) : "cc" ); //CMP could overwrite existing CC [== EFLAGS] value, hence cc in clobbers //volatile modifier on those variables unnecesary since we are modifying the register that // holds a and h at this moment if(a){ std::cout << "h > 10" << std::endl; } else { std::cout << "h <= 10" << std::endl; } }