Addition or Subtraction
Addition or Subtraction
MODEL SMALL
.STACK 100h
.DATA
.CODE
start:
mov ax,@data
mov ds,ax
mov ah,09
mov dx, offset choice_msg
int 21h
mov ah,01
int 21h
cmp al,'+'
jne subtraction
addition:
call read
call endl
add num1,bl
mov al, num1
mov result, al
call write
jmp exit
subtraction:
call read
call endl
sub num1,bl
mov al, num1
mov result, al
call write
jmp exit
;-----------------------
;procedure declarations:
proc endl
mov ah,09
mov dx, offset new_line
int 21h
ret
endp
proc read
mov ah,09
mov dx, offset first_msg
int 21h
mov ah,01
int 21h
sub al,48
mov num1,al
mov ah,01
int 21h
sub al,48
mov num2,al
mov al,num1
mul ten
add al,num2
mov num1,al
call endl
mov ah,09
mov dx, offset second_msg
int 21h
mov ah,01
int 21h
sub al,48
mov num2,al
mov ah,01
int 21h
sub al,48
mov num3,al
mov al,num2
mul ten
add al,num3
mov num2,al
ret
endp
mov al,result
mov ah,00
div ten ;div al by ten, quotient is in al
;remainder is stored in ah.
endp
exit:
mov ax, 4c00h ;This is just a failsafe exit
int 21h
END