Guest User

Untitled

a guest
Jan 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. SYS_EXIT equ 1
  2. SYS_READ equ 3
  3. SYS_WRITE equ 4
  4. STDIN equ 0
  5. STDOUT equ 1
  6.  
  7. segment .data
  8.  
  9. msg db "Please enter a digit ", 0xA,0xD
  10. len equ $- msg
  11.  
  12. segment .bss
  13.  
  14. number1 resb 2
  15. number2 resb 2
  16. result resb 1
  17. result2 resb 1
  18.  
  19.  
  20. segment .text
  21.  
  22. msg2 db "Please enter a second digit", 0xA,0xD
  23. len2 equ $- msg2
  24.  
  25. msg3 db "The sum is: "
  26. len3 equ $- msg3
  27.  
  28. msg4 db "The minus is: "
  29. len4 equ $- msg4
  30.  
  31. global _start
  32.  
  33. _start:
  34.  
  35. mov eax, SYS_WRITE ; System write
  36. mov ebx, STDOUT ; System output
  37. mov ecx, msg ; What to write
  38. mov edx, len ; Length to write
  39. int 0x80 ; Interupt Kernel
  40.  
  41. mov eax, SYS_READ ; System read
  42. mov ebx, STDIN ;
  43. mov ecx, number1
  44. mov edx, 2
  45. int 0x80
  46.  
  47. mov eax, SYS_WRITE
  48. mov ebx, STDOUT
  49. mov ecx, msg2
  50. mov edx, len2
  51. int 0x80
  52.  
  53. mov eax, SYS_READ
  54. mov ebx, STDIN
  55. mov ecx, number2
  56. mov edx, 2
  57. int 0x80
  58.  
  59.  
  60. call add
  61.  
  62.  
  63.  
  64. add:
  65. mov eax, SYS_WRITE
  66. mov ebx, STDOUT
  67. mov ecx, msg3
  68. mov edx, len3
  69. int 0x80
  70.  
  71. ;load number1 into eax and subtract '0' to convert from ASCII to decimal
  72. mov eax, [number1]
  73. sub eax, '0'
  74. ; do the same for number2
  75. mov ebx, [number2]
  76. sub ebx, '0'
  77.  
  78. ; add eax and ebx, storing the result in eax
  79. add eax, ebx
  80. ; add '0' to eax to convert the digit from decimal to ASCII
  81. add eax, '0'
  82.  
  83. ; store the result in result
  84. mov [result], eax
  85.  
  86. ; print the result digit
  87. mov eax, SYS_WRITE
  88. mov ebx, STDOUT
  89. mov ecx, result
  90. mov edx, 1
  91. int 0x80
  92.  
  93. ret
  94.  
  95. minus:
  96.  
  97. mov eax, SYS_WRITE
  98. mov ebx, STDOUT
  99. mov ecx, msg4
  100. mov edx, len4
  101. int 0x80
  102.  
  103. ;load number1 into eax and subtract '0' to convert from ASCII to decimal
  104. mov eax, [number1]
  105. sub eax, '0'
  106. ; do the same for number2
  107. mov ebx, [number2]
  108. sub ebx, '0'
  109.  
  110. ; add eax and ebx, storing the result in eax
  111. sub eax, ebx
  112. ; add '0' to eax to convert the digit from decimal to ASCII
  113. add eax, '0'
  114.  
  115. ; store the result in result
  116. mov [result2], eax
  117.  
  118. ; print the result digit
  119. mov eax, SYS_WRITE
  120. mov ebx, STDOUT
  121. mov ecx, result
  122. mov edx, 1
  123. int 0x80
  124.  
  125. ret
  126.  
  127. mul:
  128.  
  129. ;load number1 into eax and subtract '0' to convert from ASCII to decimal
  130. mov al, [number1]
  131. sub al, '0'
  132. ; do the same for number2
  133. mov bl, [number2]
  134. sub bl, '0'
  135.  
  136. ; add eax and ebx, storing the result in eax
  137. mul bl
  138. ; add '0' to eax to convert the digit from decimal to ASCII
  139. add al, '0'
  140.  
  141. ; store the result in result
  142. mov [result], al
  143.  
  144. ; print the result digit
  145. mov eax, SYS_WRITE
  146. mov ebx, STDOUT
  147. mov ecx, result
  148. mov edx, 1
  149. int 0x80
  150.  
  151. ret
  152.  
  153.  
  154. exit:
  155. mov eax, SYS_EXIT
  156. xor ebx, ebx
  157. int 0x80
Add Comment
Please, Sign In to add comment