Advertisement
Nick_vibes

Untitled

Feb 26th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. ;nasm 2.11.08
  2.  
  3. section .bss
  4. var1 resb 2
  5. opp resb 2
  6. var2 resb 2
  7. period resb 2;2
  8. answer resb 1;2
  9.  
  10. section .data
  11. msg db "= ",
  12. len equ $- msg
  13.  
  14. skp db " ", 0xA
  15. len3 equ $- msg
  16.  
  17.  
  18. section .text
  19. global _start
  20. _start:
  21.  
  22. next:
  23.  
  24. mov eax, 4
  25. mov ebx, 1
  26. mov ecx, skp
  27. mov edx, 2
  28. int 0x80
  29.  
  30. mov eax, 3; gets the first variable
  31. mov ebx, 0
  32. mov ecx, var1
  33. mov edx, 2
  34. int 0x80
  35.  
  36. mov eax, [var1]
  37. cmp al, '.'
  38. je per
  39.  
  40. mov eax, 3; gets the opperator
  41. mov ebx, 0
  42. mov ecx, opp
  43. mov edx, 2
  44. int 0x80
  45.  
  46. mov eax, 3 ; gets the second variable
  47. mov ebx, 0
  48. mov ecx, var2
  49. mov edx, 2
  50. int 0x80
  51.  
  52. mov eax, 3 ; gets the period at the end if it is there if no thtere is a space
  53. mov ebx, 0
  54. mov ecx, period
  55. mov edx, 1
  56. int 0x80
  57.  
  58. ;/////////////////////////////////////////////////////////
  59.  
  60. mov eax, 4; prints first varible for output
  61. mov ebx, 1
  62. mov ecx, var1
  63. mov edx, 2
  64. int 0x80
  65.  
  66. mov eax, 4; prints operator for output
  67. mov ebx, 1
  68. mov ecx, opp
  69. mov edx, 2
  70. int 0x80
  71.  
  72. mov eax, 4 ; prints second varible for output
  73. mov ebx, 1
  74. mov ecx, var2
  75. mov edx, 2
  76. int 0x80
  77.  
  78.  
  79. ;//////////////////////////////////////////////////////////
  80. mov eax, [opp] ; puts the opperator into eax tocheck what it is
  81.  
  82. cmp al, '+' ; if + jump to add
  83. je add_n
  84.  
  85. cmp al, '-' ; if - jump to subtract
  86. je sub_n
  87.  
  88. cmp al, '*' ; if * jump to multiply
  89. je mult
  90.  
  91. cmp al, '/' ; if / jump to divide
  92. je divi
  93.  
  94. per: ; if there is a period jump to the end
  95. jmp end
  96.  
  97. add_n: ; calls add function
  98. call add_num
  99.  
  100. sub_n: ; calls ssubtract function
  101. call sub_num
  102.  
  103. mult: ; calls multiply function
  104. call mult_num
  105.  
  106. divi: ; calls divide function
  107. call divi_num
  108.  
  109. ;//////////////////////////////////////////////////////////////////
  110. add_num:
  111. mov al, [var1] ; gets first var and puts it into decimal to preform operation
  112. sub al, '0'
  113.  
  114. mov bl, [var2]; gets second var and puts it into decimal to preform operation
  115. sub bl, '0'
  116.  
  117. add al, bl ; preforms opperation
  118. add al, '0' ; puts it back into ascii
  119. mov [answer], al; places it into answer
  120.  
  121. mov eax, 4 ; prints the equal sign
  122. mov ebx, 1
  123. mov ecx, msg
  124. mov edx, len
  125. int 0x80
  126.  
  127. mov eax, 4 ; prints the answer
  128. mov ebx, 1
  129. mov ecx, answer
  130. mov edx, 1
  131. int 0x80
  132.  
  133.  
  134. mov al, 0
  135.  
  136. ;/////////////TESTING
  137.  
  138.  
  139.  
  140.  
  141.  
  142. ;////////END TESTING
  143.  
  144. jmp next
  145. ;///////////////////////////////////////
  146.  
  147. sub_num:
  148. mov al, [var1]; gets first var and puts it into decimal to preform operation
  149. sub al, '0'
  150.  
  151. mov bl, [var2]; gets second var and puts it into decimal to preform operation
  152. sub bl, '0'
  153.  
  154. sub al, bl; preforms opperation; preforms opperation
  155. add al, '0'; puts it back into ascii; puts it back into ascii
  156. mov [answer], al; places it into answer
  157.  
  158. mov eax, 4 ; prints the equal sign
  159. mov ebx, 1
  160. mov ecx, msg
  161. mov edx, len
  162. int 0x80
  163.  
  164. mov eax, 4 ; prints the answer
  165. mov ebx, 1
  166. mov ecx, answer
  167. mov edx, 1
  168. int 0x80
  169.  
  170. jmp next
  171. ;///////////////////////////////////////
  172.  
  173. mult_num:
  174. mov al, [var1]; gets first var and puts it into decimal to preform operation
  175. sub al, '0'
  176.  
  177. mov bl, [var2]; gets second var and puts it into decimal to preform operation
  178. sub bl, '0'
  179.  
  180. mul bl; preforms opperation
  181. add al, '0'; puts it back into ascii
  182. mov [answer], al; places it into answer
  183.  
  184. mov eax, 4 ; prints the equal sign ; prints the equal sign
  185. mov ebx, 1
  186. mov ecx, msg
  187. mov edx, len
  188. int 0x80
  189.  
  190. mov eax, 4 ; prints the answer
  191. mov ebx, 1
  192. mov ecx, answer
  193. mov edx, 1
  194. int 0x80
  195.  
  196. jmp next
  197. ;///////////////////////////////////////
  198. ;DIVIDE
  199. divi_num:
  200.  
  201. mov ax, [var1]; gets first var and puts it into decimal to preform operation
  202. sub ax, '0'
  203.  
  204. mov bx, [var2]; gets second var and puts it into decimal to preform operation
  205. sub bl, '0'
  206.  
  207. div bx; preforms opperation
  208. add bx, '0'; puts it back into ascii
  209. mov [answer], bx; places it into answer
  210.  
  211. mov eax, 4 ; prints the equal sign
  212. mov ebx, 1
  213. mov ecx, msg
  214. mov edx, len
  215. int 0x80
  216.  
  217. mov eax, 4 ; prints the answer
  218. mov ebx, 1
  219. mov ecx, answer
  220. mov edx, 2
  221. int 0x80
  222.  
  223. jmp next
  224. ;///////////////////////////////////////////////////
  225.  
  226. end:
  227. mov eax,1 ; The system call for exit (sys_exit)
  228. mov ebx,0 ; Exit with return code of 0 (no error)
  229. int 80h;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement