Calculator (ASM)
Calculator (ASM)
Calculator (ASM)
.MODEL SMALL
.STACK 200H
.DATA
op_ans db 6 dup("$")
newline db 13,10,"$"
input_num1 db 10 dup("$")
input_num2 db 10 dup("$")
sum db 10 dup("$")
difference db 10 dup("$")
cont_ans db 10 dup("$")
sub_num1 db 10 dup("$")
sub_num2 db 10 dup("$")
.code
clrscr proc
push ax
int 10h
pop ax
ret
clrscr endp
readstr proc
push ax
int 21h
pop ax
ret
readstr endp
printstr proc
push ax
int 21h
pop ax
ret
printstr endp
mov ds, ax
mov es, ax
call clrscr
call printstr
call printstr
lea dx,[operation]
call printstr
call printstr
lea dx,[addition]
call printstr
call printstr
lea dx,[subtraction]
call printstr
call printstr
lea dx,[multiplication]
call printstr
call printstr
lea dx,[division]
call printstr
call printstr
lea dx,op
call printstr
mov al,op_ans[02]
mov ah,0ah
int 21h
cmp op_ans,"a"
je lbladdition
lbladdition:
call printstr
call printstr
call printstr
call printstr
mov ah,0ah
int 21h
mov ah,input_num1[02]
mov al,input_num1[03]
sub ax,3030h
call printstr
lea dx,[num2_msg]
call printstr
lea dx,input_num2
mov ah,0ah
int 21h
sub ax,3030h
aad
mov ch,al
add ch,bl
mov al,ch
aam
add ax,3030h
mov bl,ah
sub bh,30h
add bh,bl
add bh,30h
mov sum[0002],bh
mov sum[0003],al
mov sum[0005],'$'
call printstr
lea dx,[sum_msg]
call printstr
call printstr
call printstr
lblsubtraction:
call printstr
call printstr
call printstr
call printstr
mov ah,0ah
int 21h
mov ah,input_num1[02]
mov al,input_num2[03]
sub ax,3030h
mov bh,ah
mov bl,al
call printstr
lea dx,[num2_msg]
call printstr
lea dx,input_num2
mov ah,0ah
int 21h
mov ah,input_num2[0002]
mov al,input_num2[0003]
sub ax,3030h
aad
mov ch,al
sub ch,bl
mov al,bl
aam
add ax,3030h
mov bl,ah
sub bh,30h
sub bh,bl
add bh,30h
mov difference[0002],bh
mov difference[0003],al
mov difference[0005],'$'
lea dx,[newline]
call printstr
lea dx,[difference_msg]
call printstr
lea dx,difference[0002]
call printstr
int 21h
end begin