fork download
  1. .comm x,4,4
  2. .comm y,4,4
  3.  
  4. .section .rodata
  5.  
  6. format1: .string "Div : %d / %d = %.2f\n"
  7. format2: .string "Mod : %d %% %d = %d\n"
  8. format3: .string "Multiply : %u * %u = %llu\n"
  9. format4: .string "%d %d"
  10. const100: .int 100
  11.  
  12. .text
  13. .globl main
  14. .type main, @function
  15. main:
  16. subl $32, %esp # allocate space, preserve alignment
  17.  
  18. movl $format4, (%esp)
  19. movl $x, 4(%esp)
  20. movl $y, 8(%esp)
  21. call scanf
  22.  
  23. # operation divide
  24. fildl x
  25. fimul const100
  26. fidivl y
  27. # truncate to integer
  28. # use this if current FPU rounding mode
  29. # is known to be truncate
  30. # frndint
  31. # otherwise use this
  32. fnclex
  33. fnstcw (%esp) # save a copy to modify
  34. fnstcw 2(%esp) # and a copy to preserve
  35. orw $0x0c00, (%esp) # rounding mode = truncate
  36. fldcw (%esp) # activate
  37. frndint # do the truncate
  38. fldcw 2(%esp) # restore original
  39. # end of truncate code
  40. fidiv const100
  41. fstpl 12(%esp) # x / y
  42.  
  43. movl $format1, (%esp)
  44. movl x, %eax
  45. movl %eax, 4(%esp)
  46. movl y, %eax
  47. movl %eax, 8(%esp)
  48. call printf
  49.  
  50. # operation modulo
  51. movl x, %eax
  52. cltd
  53. idivl y
  54. movl $format2, (%esp)
  55. movl x, %eax
  56. movl %eax, 4(%esp)
  57. movl y, %eax
  58. movl %eax, 8(%esp)
  59. movl %edx, 12(%esp)
  60. call printf
  61.  
  62. # operation multiply
  63. movl x, %eax
  64. mull y
  65. movl $format3, (%esp)
  66. movl x, %ecx
  67. movl %ecx, 4(%esp)
  68. movl y, %ecx
  69. movl %ecx, 8(%esp)
  70. movl %eax, 12(%esp)
  71. movl %edx, 16(%esp)
  72. call printf
  73.  
  74. addl $32, %esp
  75. xor %eax, %eax
  76. ret
  77.  
Success #stdin #stdout 0.01s 1572KB
stdin
19 1000
stdout
Div : 19 / 1000 = 0.01
Mod : 19 % 1000 = 19
Multiply : 19 * 1000 = 19000