SHARE
TWEET

Untitled

a guest Feb 21st, 2020 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "CPsub64.inc"
  2.  
  3. global main
  4.  
  5. section .text
  6. main:
  7. ; initial setup
  8.     mov rcx, 1
  9.     mov rdi, 1
  10.  
  11. ; Start of addidtion
  12.  
  13. ; display what operation is being done
  14.     mov rax, 1
  15.     mov rsi, messageADD
  16.     mov rdx, lengthADD
  17.     syscall
  18.  
  19. ; print a blankline
  20.     mov rax, 1
  21.     mov rsi, blankline
  22.     mov rdx, length1
  23.     syscall
  24.  
  25. ; display the message for the first input for addition
  26.     mov rax, 1
  27.     mov rsi, message1
  28.     mov rdx, length1
  29.     syscall
  30.    
  31. ; take in the input for addidtion 1
  32.     mov rdx, 255
  33.     mov rcx, userinputADD1
  34.     mov rbx, 0
  35.     mov rax, 3
  36.     int 80h
  37.    
  38. ; covert from string to number 1
  39.     mov rdx, userinputADD1
  40.     mov rcx, 255
  41.     call ParseInteger64
  42.     mov r8, rax
  43.  
  44. ; display the message for the second input for addidtion
  45.     mov rax, 1
  46.     mov rsi, message2
  47.     mov rdx, length2
  48.     syscall
  49.    
  50. ; take in the input for addidtion 2
  51.     mov rdx, 255
  52.     mov rcx, userinputADD2
  53.     mov rbx, 0
  54.     mov rax, 3
  55.     int 80h
  56.    
  57. ; covert from string to number 2
  58.     mov rdx, userinputADD2
  59.     mov rcx, 255
  60.     call ParseInteger64
  61.     mov r9, rax
  62.  
  63. ; addidtion
  64.     add r9,r8
  65.    
  66.  
  67. ; display addidtion answer
  68.     mov rax, r9
  69.     call WriteInt
  70.  
  71. ; Print a blankline
  72.     mov rax, 1
  73.     mov rsi, blankline
  74.     mov rdx, length1
  75.     syscall
  76. ;==============================
  77.  
  78. ; Start of subtraction
  79.  
  80. ; display what operation is being done
  81.     mov rax, 1
  82.     mov rsi, messageSUB
  83.     mov rdx, lengthSUB
  84.     syscall
  85.  
  86. ; print a blankline
  87.     mov rax, 1
  88.     mov rsi, blankline
  89.     mov rdx, length1
  90.     syscall
  91.  
  92. ; display the message for the first input for subtraction
  93.     mov rax, 1
  94.     mov rsi, message1
  95.     mov rdx, length1
  96.     syscall
  97.    
  98. ; take in the input for subtraction 1
  99.     mov rdx, 255
  100.     mov rcx, userinputSUB1
  101.     mov rbx, 0
  102.     mov rax, 3
  103.     int 80h
  104.    
  105. ; covert from string to number 1
  106.     mov rdx, userinputSUB1
  107.     mov rcx, 255
  108.     call ParseInteger64
  109.     mov r8, rax
  110.  
  111. ; display the message for the second input for subtraction
  112.     mov rax, 1
  113.     mov rsi, message2
  114.     mov rdx, length2
  115.     syscall
  116.    
  117. ; take in the input for subtraction 2
  118.     mov rdx, 255
  119.     mov rcx, userinputSUB2
  120.     mov rbx, 0
  121.     mov rax, 3
  122.     int 80h
  123.    
  124. ; covert from string to number 2
  125.     mov rdx, userinputSUB2
  126.     mov rcx, 255
  127.     call ParseInteger64
  128.     mov r9, rax
  129.  
  130. ; subtraction
  131.     sub r9,r8
  132.  
  133. ; display subtraction answer
  134.     mov rax, r9
  135.     call WriteInt
  136. ;==========================================
  137.  
  138. ; Start of Multiplication
  139.  
  140. ; display what operation is being done
  141.     mov rax, 1
  142.     mov rsi, messageMUL
  143.     mov rdx, lengthMUL
  144.     syscall
  145.  
  146. ; print a blankline
  147.     mov rax, 1
  148.     mov rsi, blankline
  149.     mov rdx, length1
  150.     syscall
  151.  
  152. ; display the message for the first input for multiplication
  153.     mov rax, 1
  154.     mov rsi, message1
  155.     mov rdx, length1
  156.     syscall
  157.    
  158. ; take in the input for multiplication 1
  159.     mov rdx, 255
  160.     mov rcx, userinputMUL1
  161.     mov rbx, 0
  162.     mov rax, 3
  163.     int 80h
  164.    
  165. ; covert from string to number 1
  166.     mov rdx, userinputMUL1
  167.     mov rcx, 255
  168.     call ParseInteger64
  169.     mov r8, rax
  170.  
  171. ; display the message for the second input for multiplication
  172.     mov rax, 1
  173.     mov rsi, message2
  174.     mov rdx, length2
  175.     syscall
  176.    
  177. ; take in the input for multiplication 2
  178.     mov rdx, 255
  179.     mov rcx, userinputMUL2
  180.     mov rbx, 0
  181.     mov rax, 3
  182.     int 80h
  183.    
  184. ; covert from string to number 2
  185.     mov rdx, userinputMUL2
  186.     mov rcx, 255
  187.     call ParseInteger64
  188.     mov r9, rax
  189.  
  190. ; multiplication  
  191.     mov rax, 5
  192.     mov rsi, 4
  193.     mul rsi
  194.  
  195. ; display multiplication answer
  196.     mov rax, r8
  197.     call WriteInt
  198.  
  199. ; Print a blankline
  200.     mov rax, 1
  201.     mov rsi, blankline
  202.     mov rdx, length1
  203.     syscall
  204. ;=======================================
  205.  
  206. ;Start Division
  207.  
  208. ; display what operation is being done
  209.     mov rax, 1
  210.     mov rsi, messageDIV
  211.     mov rdx, lengthDIV
  212.     syscall
  213.    
  214. ; Take in the input
  215.     mov rdx, 255
  216.     mov rcx, userinputDIV1
  217.     mov rbx, 0
  218.     mov rax, 3
  219.     int 80h
  220.     call DumpMem   
  221.  
  222. ; Covert  from string to number
  223.     mov rdx, userinputDIV1
  224.     mov rcx, 255
  225.     call ParseInteger64
  226.     mov r8, rax
  227.  
  228. ;display the message for the second input
  229.     mov rax, 1
  230.     mov rsi, message2
  231.     mov rdx, length2
  232.     syscall
  233.    
  234. ; Take in the input
  235.     mov rdx, 255
  236.     mov rcx, userinputDIV2
  237.     mov rbx, 0
  238.     mov rax, 3
  239.     int 80h
  240.    
  241. ; Covert from string to number
  242.     mov rdx, userinputDIV2
  243.     mov rcx, 255
  244.     call ParseInteger64
  245.     mov r9, rax
  246.  
  247. ; division
  248.     ;mov rdx, 0
  249.     ;mov rax, r8
  250.     ;div r9
  251.    
  252.     mov rdx, 0
  253.     mov rax, 20
  254.     mov rsi, 4
  255.     div rsi
  256.  
  257.  
  258. ; display division answer
  259.     mov rax, r8
  260.     call WriteInt
  261.    
  262. ; Print a blankline
  263.     mov rax, 1
  264.     mov rsi, blankline
  265.     mov rdx, length1
  266.     syscall
  267.    
  268. ; exit command
  269.     mov rax, 60
  270.     xor rdi, rdi
  271.     syscall
  272.    
  273.  
  274. section .data
  275. messageADD: db "We are adding numbers:" ,0,0ah
  276. lengthADD: equ ($-messageSUB)
  277.  
  278. messageSUB: db "We are subtracting numbers now:" ,0,0ah
  279. lengthSUB: equ ($-messageSUB)
  280.  
  281. messageMUL: db "We are multiplying now:" ,0,0ah
  282. lengthMUL: equ ($-messageMUL)
  283.  
  284. messageDIV: db "We are dividing now:" ,0,0ah
  285. lengthDIV: equ ($-messageMUL)
  286.  
  287. message1: db "Please enter the first number:" ,0,0ah
  288. length1: equ ($-message1)
  289.  
  290. message2: db "Please enter the second number:" ,0,0ah
  291. length2: equ ($-message2)
  292.  
  293. blankline:db '',0,0ah
  294. lengthblank: equ ($-blankline)
  295.  
  296.  
  297. section .bss
  298. userinputADD1: resb 255 ;reserving 255 bytes
  299. userinputADD2: resb 255 ;reserving 255 bytes
  300.  
  301. userinputSUB1: resb 255 ;reserving 255 bytes
  302. userinputSUB2: resb 255 ;reserving 255 bytes
  303.  
  304. userinputMUL1: resb 255 ;reserving 255 bytes
  305. userinputMUL2: resb 255 ;reserving 255 bytes
  306.  
  307. userinputDIV1: resb 255 ;reserving 255 bytes
  308. userinputDIV2: resb 255 ;reserving 255 bytes
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top