Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views3 pages

Addition or Subtraction

Uploaded by

Diego Abad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Addition or Subtraction

Uploaded by

Diego Abad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

.

MODEL SMALL
.STACK 100h
.DATA

choice_msg db 'Addition or Subtraction?','$'


first_msg db 'Enter the first number:','$'
second_msg db 'Enter the second number:','$'
result_msg db 'The result is:','$'
new_line db 13,10,'$'
val1 db ?
num1 db ?
num2 db ?
num3 db ? ; purely a buffer variable
ten db 10
t1 db 0
t2 db 0
result db 0

.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

mov bl, num2

add num1,bl
mov al, num1
mov result, al

call write
jmp exit

subtraction:
call read
call endl

mov bl, num2

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

;The write procedure writes the decimal stored in result.


;by dividing by ten it seperates the two digits as quotient
;and remainder. Then it outputs the quotient and remainder
;in ascii form.
proc write
mov dx,offset result_msg
mov ah,09h
int 21h

mov al,result
mov ah,00
div ten ;div al by ten, quotient is in al
;remainder is stored in ah.

mov dl,ah ;move the remainder to dl


mov t2,dl ;store the remainder in t2

mov dl,al ;move quotient into dl


add dl,48 ;add 48 to dl, to convert it to ascii
mov ah,02h ;char display interupt code
int 21h ;display char in dl register

mov dl,t2 ;move remainder to t2


add dl,48 ;convert it to ascii by adding 48
mov ah,02h ;display character in dl interupt code
int 21h ;diplays contents of dl

call endl ;output a new line


ret

endp

exit:
mov ax, 4c00h ;This is just a failsafe exit
int 21h

END

You might also like