Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. SYS_EXIT equ 1 ; Allocation if information for better understanding of what certain numbers do
  2. SYS_READ equ 3
  3. SYS_WRITE equ 4
  4. STDIN equ 0
  5. STDOUT equ 1
  6.  
  7. section .data
  8. msg1 db "= "
  9. len1 equ $- msg1
  10.  
  11. msg2 db "Inside Add"
  12. len2 equ $- msg2
  13.  
  14. msg3 db "Inside Sub"
  15. len3 equ $- msg3
  16.  
  17. msg4 db "Debug"
  18. len4 equ $- msg4
  19.  
  20. section .bss
  21. var1 resb 2
  22. op resb 2
  23. var2 resb 2
  24. res resb 2
  25.  
  26. section .text
  27.  
  28. global _start
  29. _start:
  30.  
  31. CheckOp:
  32. ;Reads STDIN
  33. mov eax,3
  34. mov ebx,0
  35. mov ecx, var1
  36. mov edx, 2
  37. int 80h
  38.  
  39. mov al, [var1]
  40. cmp al, '.' ;will hold as a place stopper for the string loop
  41. je end
  42.  
  43. ;Reads STDIN
  44. mov eax,3
  45. mov ebx,0
  46. mov ecx, op
  47. mov edx, 2
  48. int 80h
  49.  
  50. ;Reads STDIN
  51. mov eax,3
  52. mov ebx,0
  53. mov ecx, var2
  54. mov edx, 1
  55. int 80h
  56.  
  57. ;;output
  58. mov eax,4
  59. mov ebx,1
  60. mov ecx, var1
  61. mov edx, 2
  62. int 80h
  63.  
  64. mov eax,4
  65. mov ebx,1
  66. mov ecx, op
  67. mov edx, 2
  68. int 80h
  69.  
  70. mov eax,4
  71. mov ebx,1
  72. mov ecx, var2
  73. mov edx, 2
  74. int 80h
  75.  
  76. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  77.  
  78. mov al, [op]
  79.  
  80. cmp al,'+' ; if addition, jump to callADD (addition procedure call)
  81. je callADD
  82.  
  83. cmp al,'-'
  84. je callSUB
  85.  
  86. callADD:
  87. call ADD
  88.  
  89. callSUB:
  90. call SUB
  91.  
  92. ADD:
  93. ;Debug Message
  94. mov eax,4
  95. mov ebx,1
  96. mov ecx, msg2
  97. mov edx, len2
  98. int 80h
  99. ; moving the first number to eax register and second number to ebx
  100. ; and subtracting ascii '0' to convert it into a decimal number
  101. mov al, [var1]
  102. sub al, '0'
  103. mov bl, [var2]
  104. sub bl, '0'
  105. ; add eax and ebx
  106. add al, bl
  107. ; add '0' to to convert the sum from decimal to ASCII
  108. add al, '0'
  109. ; storing the sum in memory location res
  110. mov [res], al
  111.  
  112. mov eax,4 ;Prints equals sign
  113. mov ebx,1
  114. mov ecx, msg1
  115. mov edx, len1
  116. int 80h
  117.  
  118. mov eax,4 ;Prints answer
  119. mov ebx,1
  120. mov ecx, res
  121. mov edx, 2
  122. int 80h
  123. jmp CheckOp
  124.  
  125.  
  126. SUB:
  127. mov eax,4
  128. mov ebx,1
  129. mov ecx, msg3
  130. mov edx, len3
  131. int 80h
  132. ; moving the first number to eax register and second number to ebx
  133. ; and subtracting ascii '0' to convert it into a decimal number
  134. mov al, [var1]
  135. sub bl, '0'
  136. mov bl, [var2]
  137. sub bl, '0'
  138. ; subtract eax and ebx
  139. sub al, bl
  140. ; add '0' to to convert the sum from decimal to ASCII
  141. add al, '0'
  142. ; storing the sum in memory location res
  143. mov [res], al
  144.  
  145. mov eax,4 ;Prints equals sign
  146. mov ebx,1
  147. mov ecx, msg1
  148. mov edx, len1
  149. int 80h
  150.  
  151. mov eax,4 ;Prints answer
  152. mov ebx,1
  153. mov ecx, res
  154. mov edx, 2
  155. int 80h
  156. jmp CheckOp
  157.  
  158.  
  159. ;Output: ;Output Statements
  160.  
  161.  
  162.  
  163.  
  164. end:
  165. mov eax,1
  166. mov ebx,0
  167. int 80h;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement