; Macro for printing messages
printmsg macro msg
push ax
push bx
push cx
push dx
LEA dx,msg
mov ah,09h
int 21h
pop dx
pop cx
pop bx
pop ax
endm
; begins data segment
.data
msg1 db 0ah,0dh,"Enter first number NUM1= $"
msg2 db 0ah,0dh,"Enter second number NUM2= $"
msg3 db 0ah,0dh,"1=> Addition 2=>Substraction 3=>Multiplication 4=>Division: $"
msg4 db 0ah,0dh,"Enter your option : $"
msg10 db 0ah,0dh," $"
msg5 db 0ah,0dh," NUM1 + NUM2 = $"
msg6 db 0ah,0dh," NUM1 - NUM2 = $"
msg7 db 0ah,0dh," NUM1 * NUM2 = $"
msg8 db 0ah,0dh," NUM1 / NUM2 = $"
msg9 db 0ah,0dh,"NO SUCH OPTION $"
num dw 0
cnt dw 0
choice dw 0
a dw 0
b dw 0
output dw 0
; begins code segment
.code
mov ax,@data ; code segment get the address of data segment of this program
mov ds,ax
printmsg msg1 ; Print the message in msg1 of data segemnt
call readnum ; Use procedure to read the number
mov ax,num ; Store this number in ax register
mov a,ax
printmsg msg10 ; printing a new line
printmsg msg2
call readnum
mov bx,num
mov b,bx
printmsg msg3 ; printing menu
loop1:
printmsg msg10 ; printing a new line
printmsg msg4
call readnum
mov ax,num
mov choice,ax
cmp choice,01
je addi
cmp choice,02
je subt
cmp choice,03
je multi
cmp choice,04
je divi
printmsg msg10 ; printing a new line
printmsg msg9
call printnum
jmp ex
addi:
printmsg msg10 ; printing a new line
printmsg msg5 ; Print the message in msg5
mov ax,a ; move the NUM1 to ax register
add ax,b ; add the ax register with NUM2 whish is in varisble b and the result will be in ax register
mov num,ax ; Moving this to varaible num for printing
call printnum ; call the print procedure for printing.
jmp loop1
subt:
printmsg msg10 ; printing a new line
printmsg msg6
mov ax,a
mov bx,b
sub ax,bx
mov num,ax
call printnum
jmp loop1
multi:
printmsg msg10 ; printing a new line
printmsg msg7
mov ax,a
mov bx,b
mul bx ; Multilying with ax register will give ax*bx and the result will be in ax register.
mov num,ax ;
call printnum
jmp loop1
divi:
printmsg msg10 ; printing a new line
printmsg msg8
mov ax,a
mov bx,b
XOR dx,dx ; clearing dx register for storing higher order bits if any after multiplication
div bx
mov num,ax
call printnum
jmp ex
ex: ; Interrruot to exit to the dos
mov ah,4ch
int 21h
; Procedure to read a number to the variable num declared in the data segment
readnum proc near
push ax
push bx
push cx
push dx
mov num,00
r1:
mov ah,01h
int 21h
cmp al,0dh
je r2
mov cx,ax
and cx,00ffh
sub cx,30h
mov bx,10
mov ax,num
mul bx
add ax,cx
mov num,ax
jmp r1
r2:
pop dx
pop cx
pop bx
pop ax
ret
readnum endp
; Procedure to print a number to the variable num declared in the data segment
printnum proc near
push ax
push bx
push cx
push dx
mov ax,num
mov bx,10
p1:
mov dx,00
div bx
push dx
inc cnt
cmp ax,00
jne p1
p2:
cmp cnt,00
je p3
pop dx
add dl,30h
mov ah,02h
int 21h
dec cnt
jmp p2
p3:
pop dx
pop cx
pop bx
pop ax
ret
printnum endp
end
To embed this project on your website, copy the following code and paste it into your website's HTML: