fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. int main() {
  5. int x = -5;
  6. int a = 3;
  7. int y1 = 0;
  8. int y2 = 0;
  9. int y = 0;
  10.  
  11.  
  12. __asm__ (
  13. "movl %[x], %%eax \n\t"
  14. "cmpl $0, %%eax \n\t"
  15. "jl negative_x \n\t"
  16. "subl %[a], %%eax \n\t"
  17. "movl %%eax, %[y1] \n\t"
  18. "jmp done_y1 \n\t"
  19. "negative_x: \n\t"
  20. "negl %%eax \n\t"
  21. "movl %%eax, %[y1] \n\t"
  22. "done_y1: \n\t"
  23. : [y1] "=r" (y1)
  24. : [x] "r" (x), [a] "r" (a)
  25. : "eax"
  26. );
  27.  
  28.  
  29. __asm__ (
  30. "movl %[x], %%eax \n\t"
  31. "movl $3, %%ebx \n\t"
  32. "cdq \n\t"
  33. "idivl %%ebx \n\t"
  34. "cmpl $1, %%edx \n\t"
  35. "je mod_equal_one \n\t"
  36. "movl $7, %[y2] \n\t"
  37. "jmp done_y2 \n\t"
  38. "mod_equal_one: \n\t"
  39. "addl %[a], %[x] \n\t"
  40. "movl %[x], %[y2] \n\t"
  41. "done_y2: \n\t"
  42. : [y2] "=r" (y2)
  43. : [x] "r" (x), [a] "r" (a)
  44. : "eax", "ebx", "edx"
  45. );
  46.  
  47.  
  48. __asm__ (
  49. "movl %[y1], %%eax \n\t"
  50. "subl %[y2], %%eax \n\t"
  51. "movl %%eax, %[y] \n\t"
  52. : [y] "=r" (y)
  53. : [y1] "r" (y1), [y2] "r" (y2)
  54. : "eax"
  55. );
  56.  
  57. std::cout << "y1: " << y1 << std::endl;
  58. std::cout << "y2: " << y2 << std::endl;
  59. std::cout << "y: " << y << std::endl;
  60.  
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
y1: 5
y2: 7
y: -2