Advertisement
NB52053

CALC

Sep 4th, 2018
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. org 100h
  2. .stack 100h
  3.  
  4. .data  
  5.  
  6. count db 0
  7. result dw 0
  8. numb1 dw 0
  9. numb2 dw 0  
  10. adr dw 0
  11. sbr dw 0
  12. mlr dw 0
  13. qr db 0
  14. qm dw 0
  15. newinput db ?  
  16. nl db 0ah,0dh,'$'  
  17. msg db "Please Enter The Numbers:  $"  
  18. ms1 db "Number1: $"
  19. ms2 db "    Number2: $"  
  20. ad db "Addition: $"
  21. sb db "Subtraction: $"
  22. ml db "Multiplication: $"
  23. q db "Qoutient: $"
  24. r db "Remainder: $"
  25.    
  26. .code  
  27.  
  28.  
  29.  
  30. newline macro
  31.     ;line gap
  32.     push ax
  33.    
  34.     mov ah,9
  35.     lea dx,nl
  36.     int 21h
  37. pop ax
  38.  
  39. endm newline
  40.  
  41. print1 macro x
  42.     ;x  print
  43.     push ax
  44.     push dx
  45.  
  46.  
  47.     mov dx,x
  48.     add dx,'0'
  49.     mov ah,2
  50.     int 21h
  51.    
  52.     pop dx
  53.     pop ax
  54. endm print1
  55.  
  56. main proc
  57.     mov dx,@data
  58.     mov ds,dx  
  59.    
  60.     lea dx,msg
  61.     mov ah,9
  62.     int 21h
  63.     newline
  64.    
  65.     call scanAX
  66.    newline
  67.     ;mov ax,result
  68.    
  69.    
  70.     mov bx,result
  71.     mov numb1,bx
  72.    
  73.  
  74.    
  75.     call scanAX
  76.    newline
  77.  
  78.    
  79.     lea dx,ms1
  80.     mov ah,9
  81.     int 21h
  82.      
  83.     mov bx,result
  84.     mov numb2,bx
  85.    
  86.     mov ax,numb1
  87.     call printAX
  88.    
  89.     lea dx,ms2
  90.     mov ah,9
  91.     int 21h
  92.    
  93.     mov ax,numb2
  94.     call printAX
  95.    
  96.     newline  
  97.    
  98.     lea dx,ad
  99.     mov ah,9
  100.     int 21h
  101.    
  102.     call addnum
  103.     newline  
  104.    
  105.     lea dx,sb
  106.     mov ah,9
  107.     int 21h
  108.    
  109.     call subnum
  110.     newline
  111.  
  112.     lea dx,ml
  113.     mov ah,9
  114.     int 21h
  115.    
  116.     call mulnum
  117.     newline    
  118.  
  119.     lea dx,q
  120.     mov ah,9
  121.     int 21h
  122.    
  123.     call divnum
  124.     newline
  125.    
  126.    
  127.     mov ah,4ch
  128.     int 21h
  129. endp main
  130.  
  131. printAX proc
  132.     push ax
  133.     push bx
  134.    
  135.     mov bx,10
  136.    
  137.     processing:
  138.    
  139.     mov dx,0
  140.     div bx ;AX=AX/10, DX=AX%10
  141.     push dx
  142.     inc count
  143.     cmp ax,0
  144.     je printing
  145.     jmp processing
  146.    
  147.     printing:
  148.     cmp count,0
  149.     je done
  150.     dec count
  151.     pop dx
  152.     print1 dx
  153.     jmp printing
  154.    
  155.     done:
  156.    
  157.     pop bx
  158.     pop ax
  159.    
  160.     ret
  161. endp printAX  
  162.  
  163. scanAX proc  
  164.     push bx
  165.     push dx
  166.    
  167.     mov bx,10  ;base
  168.     mov ax,0   ;init ax=0
  169.     mov result,0
  170.    
  171.     scanprocess:
  172.     mov ah,1
  173.     int 21h
  174.     cmp al,0dh ;checking if enter is pressed
  175.     je scandone  
  176.     ;AX=0        
  177.     mov newinput,al
  178.     sub newinput,'0'
  179.    
  180.     ;result=result*10+newinput
  181.    
  182.     mov ax,result
  183.     mul bx ;dx:ax=ax*bx  
  184.     add al,newinput
  185.     mov result,ax
  186.    
  187.     jmp scanprocess
  188.    
  189.     scandone:
  190.    
  191.    
  192.     pop dx
  193.     pop bx
  194.     mov ax,result
  195.     ret
  196. endp scanAX    
  197.  
  198. addnum proc
  199.  
  200.  mov cx,numb1
  201.  add cx,numb2
  202.  mov adr,cx
  203.  mov ax,adr
  204.  call printAX
  205.  
  206.   ret
  207. endp addnum
  208.  
  209. subnum proc
  210.    
  211.  mov cx,numb1
  212.  sub cx,numb2
  213.  mov sbr,cx
  214.  mov ax,sbr
  215.  call printAX
  216.  ret  
  217. endp subnum
  218.  
  219. mulnum proc
  220.  mov ax,numb1
  221.  mul numb2
  222.  mov mlr,ax
  223.  call printAX
  224.  ret  
  225. endp mulnum
  226.  
  227. divnum proc
  228.  mov dx,0  
  229.  
  230.  mov ax,numb1
  231.  mov bx,numb2
  232.  div bx
  233.  mov qr,al
  234.  mov qm,dx
  235.  call printAX
  236.  
  237.  newline
  238.  lea dx,r
  239.  mov ah,9
  240.  int 21h
  241.  
  242.  
  243. mov ax,qm
  244. call printAX
  245.  
  246.  ret  
  247. endp divnum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement