fork download
  1. section .bss
  2. buffer resb 20
  3. inbuf resb 1
  4. num1 resd 1
  5. num2 resd 1
  6.  
  7. section .text
  8. global _start
  9.  
  10. _start:
  11. call scan_int
  12. mov [num1], eax
  13.  
  14. call scan_int
  15. mov [num2], eax
  16.  
  17. mov eax, [num1]
  18. add eax, [num2]
  19. push eax
  20. call print_int
  21.  
  22. mov eax, [num1]
  23. imul eax, [num2]
  24. push eax
  25. call print_int
  26.  
  27. mov eax, 1
  28. xor ebx, ebx
  29. int 0x80
  30.  
  31. scan_int:
  32. push ebp
  33. mov ebp, esp
  34. push ebx
  35. push ecx
  36. push edx
  37. push esi
  38. push edi
  39.  
  40. xor esi, esi
  41. xor edi, edi
  42.  
  43. .skip_ws:
  44. mov eax, 3
  45. mov ebx, 0
  46. mov ecx, inbuf
  47. mov edx, 1
  48. int 0x80
  49. cmp eax, 0
  50. je .done
  51.  
  52. mov al, [inbuf]
  53. cmp al, ' '
  54. je .skip_ws
  55. cmp al, 9
  56. je .skip_ws
  57. cmp al, 10
  58. je .skip_ws
  59. cmp al, 13
  60. je .skip_ws
  61.  
  62. cmp al, '-'
  63. jne .check_plus
  64. mov edi, 1
  65. jmp .read_digits
  66.  
  67. .check_plus:
  68. cmp al, '+'
  69. je .read_digits
  70.  
  71. .first_digit:
  72. sub al, '0'
  73. cmp al, 9
  74. ja .done
  75. movzx esi, al
  76.  
  77. .read_digits:
  78. mov eax, 3
  79. mov ebx, 0
  80. mov ecx, inbuf
  81. mov edx, 1
  82. int 0x80
  83. cmp eax, 0
  84. je .done
  85.  
  86. mov al, [inbuf]
  87. sub al, '0'
  88. cmp al, 9
  89. ja .done
  90.  
  91. movzx eax, al
  92. imul esi, esi, 10
  93. add esi, eax
  94. jmp .read_digits
  95.  
  96. .done:
  97. mov eax, esi
  98. test edi, edi
  99. jz .ret
  100. neg eax
  101.  
  102. .ret:
  103. pop edi
  104. pop esi
  105. pop edx
  106. pop ecx
  107. pop ebx
  108. pop ebp
  109. ret
  110.  
  111. print_int:
  112. push ebp
  113. mov ebp, esp
  114. push ebx
  115. push ecx
  116. push edx
  117. push esi
  118. push edi
  119.  
  120. mov ecx, [ebp+8]
  121. mov edi, 18
  122. mov byte [buffer + 18], 0xA
  123. mov byte [buffer + 19], 0
  124.  
  125. cmp ecx, 0
  126. jge .positive
  127. mov ebx, 1
  128. neg ecx
  129. jmp .convert
  130.  
  131. .positive:
  132. xor ebx, ebx
  133.  
  134. .convert:
  135. mov esi, 10
  136.  
  137. .loop:
  138. mov eax, ecx
  139. xor edx, edx
  140. div esi
  141. mov ecx, eax
  142. add edx, '0'
  143. dec edi
  144. mov byte [buffer + edi], dl
  145. cmp ecx, 0
  146. jne .loop
  147.  
  148. test ebx, ebx
  149. jz .output
  150. dec edi
  151. mov byte [buffer + edi], '-'
  152.  
  153. .output:
  154. mov eax, 4
  155. mov ebx, 1
  156. mov ecx, buffer
  157. add ecx, edi
  158. mov edx, 19
  159. sub edx, edi
  160. int 0x80
  161.  
  162. pop edi
  163. pop esi
  164. pop edx
  165. pop ecx
  166. pop ebx
  167. pop ebp
  168. ret
Success #stdin #stdout 0s 544KB
stdin
4
8
stdout
12
32