Advertisement
xladomaz

Pretty input 2 numbers and output result of summ this number

Nov 10th, 2019
1,091
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data    segment
  2.         a dw ?
  3.         nmb db ?
  4.         answer db 0h
  5.        
  6.         result db 0h
  7.        
  8.         ax_temp dw ?
  9.         bx_temp dw ?
  10. data    ends
  11.  
  12. code    segment
  13.         assume cs:code, ds:data
  14. main:   mov dx, data
  15.         mov ds, dx
  16.  
  17.         mov dx, 0B800h ; Base of videomemory;
  18.         mov es, dx
  19.         xor di, di
  20.         xor dx, dx ; Clear display;
  21.         mov ax, 0720h
  22.         mov cx, 80*25
  23.         rep stosw
  24.         jmp gen
  25.  
  26. outp_n:
  27.         add di, 2
  28.         mov ax, 0730h
  29.         add al, nmb
  30.         mov es:[di], ax
  31. ret
  32.  
  33. start:  mov cx, 02h
  34. inloop: in  al, 60h
  35.         cmp al, bl
  36.         je  inloop
  37.         mov bl, al
  38.         cmp al, 01h
  39.         jne NotEsc
  40.         jmp quit
  41. NotEsc: cmp al, 0Bh
  42.         jne CkInNum
  43.         mov a, 0
  44.         mov es:[di], 0730h
  45.         jmp NxtNum
  46. CkInNum:cmp al, 02h ; check scancode in range;
  47.         jl Not9
  48.         cmp al, 0Ah
  49.         jg Not9
  50.         mov ah, 0h
  51.         mov si, ax
  52.         dec si
  53.         mov a, si
  54.         add si, 0730h
  55.         mov es:[di], si
  56.         jmp NxtNum
  57. Not9:   jmp inloop
  58. NxtNum:
  59.         mov ax_temp, ax ; Answer;
  60.         mov bx_temp, bx
  61.         mov bl, 0Ah
  62.         mov al, answer
  63.         mul bl
  64.         add ax, a
  65.         mov answer, al
  66.         mov ax, ax_temp
  67.         mov bx, bx_temp
  68.        
  69.         inc di
  70.         inc di
  71.         dec cx
  72.        
  73.         jnz Not9
  74.         mov ax, 0h
  75. ret
  76.  
  77. gen:    
  78.         mov di, 0 ; Input 2 numbers;
  79.         call start
  80.         mov es:[di], 072Bh ; 2B - ascii +;
  81.         mov al, result
  82.         add al, answer
  83.         mov result, al
  84.         mov answer, 0h
  85.         add di, 2
  86.         call start
  87.         mov es:[di], 073Dh ; 3D - ascii =;
  88.         mov al, result
  89.         add al, answer
  90.        
  91.         mov bl, 0Ah
  92.         div bl ; Get div of number;
  93.  
  94.         mov nmb, al ; Number output;
  95.         mov bl, ah
  96.         call outp_n
  97.         mov nmb, bl
  98.         call outp_n
  99.        
  100. pause:  in al, 60h
  101.         cmp al, 01h
  102.         jne pause
  103. quit:   mov ax, 4C00h
  104.         int  21h
  105. code    ends
  106.         end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement