I need help with my code. this is a simple calculator. My addition seems to work fine. but in subtraction, when the answer is only one digit.. the first digit seems messed up. Special character shows up. This program is supposed to be accepting 2 digit number, example 02 + 04 = 06.. My addition works fine but im having problems with subtraction. anybody here who could assist me with this? is anything wrong with my code? thanks in advance

``````DOSSEG
.MODEL SMALL
.STACK 200H
.DATA

calc		db	"***CALCULATOR ***\$"
operation	db	"Select an Operation\$"
subtraction	db	"[b] Subtraction\$"
multiplication	db	"[c] Multiplication\$"
division	db	"[d] Division\$"
op		db	"Your Operation : \$"
op_ans		db	6 dup("\$")
newline		db	13,10,"\$"
num1_msg	db	"Input First Number : \$"
input_num1	db	10 dup("\$")
num2_msg	db	"Input Second Number : \$"
input_num2	db	10 dup("\$")
sum_msg		db	"The Sum is : \$"
sum		db	10 dup("\$")
subtraction_wel db	"You have chosen Subtraction \$"
difference_msg  db	"The Difference is : \$"
difference 	db	10 dup("\$")
continue	db	"Would you like to continue?[y/n] : "
cont_ans	db	10 dup("\$")
sub_num1	db	10 dup("\$")
sub_num2	db	10 dup("\$")
mul_wel		db	"You have chosen Multiplication \$"

.code

clrscr	proc
push ax
mov al, 03h
mov ah, 00h
int 10h
pop ax
ret
clrscr	endp

push ax
mov ah, 0ah
int 21h
pop ax
ret

printstr proc
push ax
mov ah, 09h
int 21h
pop ax
ret
printstr endp
begin: mov ax, @data
mov ds, ax
mov es, ax
call clrscr
lbl1:	lea dx,[calc]
call printstr
lea dx, newline
call printstr
lea dx,[operation]
call printstr
lea dx, newline
call printstr

call printstr

lea dx, newline
call printstr
lea dx,[subtraction]
call printstr

lea dx, newline
call printstr
lea dx,[multiplication]
call printstr
lea dx, newline
call printstr
lea dx,[division]
call printstr
lea dx, newline
call printstr
lea dx,op
call printstr
mov al,op_ans
mov ah,0ah
int 21h
cmp op_ans,"a"
lea dx, newline
call printstr

call printstr
lea dx, newline
call printstr
lea dx, [num1_msg]
call printstr
lea dx, input_num1
mov ah,0ah
int 21h
mov ah,input_num1
mov al,input_num1
sub ax,3030h
mov bl,al   ;< --- x9
mov bh,ah   ;< --- 9x
lea dx, newline
call printstr
lea dx,[num2_msg]
call printstr
lea dx,input_num2
mov ah,0ah
int 21h
mov ah, input_num2
mov al, input_num2
sub ax,3030h
mov ch,al
mov al,ch
aam
mov bl,ah
sub bh,30h
mov sum,bh
mov sum,al
mov sum,'\$'
lea dx, newline
call printstr
lea dx,[sum_msg]
call printstr
lea dx, sum
call printstr
lea dx, newline
call printstr
lblsubtraction:
lea dx, newline
call printstr
lea dx, [subtraction_wel]
call printstr
lea dx, newline
call printstr
lea dx, [num1_msg]
call printstr
lea dx, input_num1
mov ah,0ah
int 21h
mov ah,input_num1
mov al,input_num2
sub ax,3030h
mov bh,ah
mov bl,al
lea dx, newline
call printstr
lea dx,[num2_msg]
call printstr

lea dx,input_num2
mov ah,0ah
int 21h
mov ah,input_num2
mov al,input_num2
sub ax,3030h
mov ch,al
sub ch,bl
mov al,bl
aam
mov bl,ah
sub bh,30h
sub bh,bl
mov difference,bh
mov difference,al
mov difference,'\$'
lea dx,[newline]
call printstr

lea dx,[difference_msg]
call printstr

lea dx,difference
call printstr
mov ah, 4ch
int 21h
end begin``````
Salem commented: Try using code tags like you're supposed to, and not colour tags. -4

I need help with my code. this is a simple calculator. My addition seems to work fine. but in subtraction, when the answer is only one digit.. the first digit seems messed up. Special character shows up. This program is supposed to be accepting 2 digit number, example 02 + 04 = 06.. My addition works fine but im having problems with subtraction. anybody here who could assist me with this? is anything wrong with my code? thanks in advance

``````DOSSEG
.MODEL SMALL
.STACK 200H
.DATA

calc		db	"***CALCULATOR ***\$"
operation	db	"Select an Operation\$"
subtraction	db	"[b] Subtraction\$"
multiplication	db	"[c] Multiplication\$"
division	db	"[d] Division\$"
op		db	"Your Operation : \$"
op_ans		db	6 dup("\$")
newline		db	13,10,"\$"
num1_msg	db	"Input First Number : \$"
input_num1	db	10 dup("\$")
num2_msg	db	"Input Second Number : \$"
input_num2	db	10 dup("\$")
sum_msg		db	"The Sum is : \$"
sum		db	10 dup("\$")
subtraction_wel db	"You have chosen Subtraction \$"
difference_msg  db	"The Difference is : \$"
difference 	db	10 dup("\$")
continue	db	"Would you like to continue?[y/n] : "
cont_ans	db	10 dup("\$")
sub_num1	db	10 dup("\$")
sub_num2	db	10 dup("\$")
mul_wel		db	"You have chosen Multiplication \$"

.code

clrscr	proc
push ax
mov al, 03h
mov ah, 00h
int 10h
pop ax
ret
clrscr	endp

push ax
mov ah, 0ah
int 21h
pop ax
ret

printstr proc
push ax
mov ah, 09h
int 21h
pop ax
ret
printstr endp
begin: mov ax, @data
mov ds, ax
mov es, ax
call clrscr
lbl1:	lea dx,[calc]
call printstr
lea dx, newline
call printstr
lea dx,[operation]
call printstr
lea dx, newline
call printstr

call printstr

lea dx, newline
call printstr
lea dx,[subtraction]
call printstr

lea dx, newline
call printstr
lea dx,[multiplication]
call printstr
lea dx, newline
call printstr
lea dx,[division]
call printstr
lea dx, newline
call printstr
lea dx,op
call printstr
mov al,op_ans
mov ah,0ah
int 21h
cmp op_ans,"a"
lea dx, newline
call printstr

call printstr
lea dx, newline
call printstr
lea dx, [num1_msg]
call printstr
lea dx, input_num1
mov ah,0ah
int 21h
mov ah,input_num1
mov al,input_num1
sub ax,3030h
mov bl,al   ;< --- x9
mov bh,ah   ;< --- 9x
lea dx, newline
call printstr
lea dx,[num2_msg]
call printstr
lea dx,input_num2
mov ah,0ah
int 21h
mov ah, input_num2
mov al, input_num2
sub ax,3030h
mov ch,al
mov al,ch
aam
mov bl,ah
sub bh,30h
mov sum,bh
mov sum,al
mov sum,'\$'
lea dx, newline
call printstr
lea dx,[sum_msg]
call printstr
lea dx, sum
call printstr
lea dx, newline
call printstr
lblsubtraction:
lea dx, newline
call printstr
lea dx, [subtraction_wel]
call printstr
lea dx, newline
call printstr
lea dx, [num1_msg]
call printstr
lea dx, input_num1
mov ah,0ah
int 21h
mov ah,input_num1
mov al,input_num2
sub ax,3030h
mov bh,ah
mov bl,al
lea dx, newline
call printstr
lea dx,[num2_msg]
call printstr

lea dx,input_num2
mov ah,0ah
int 21h
mov ah,input_num2
mov al,input_num2
sub ax,3030h
mov ch,al
sub ch,bl
mov al,bl
aam
mov bl,ah
sub bh,30h
sub bh,bl
mov difference,bh
mov difference,al
mov difference,'\$'
lea dx,[newline]
call printstr

lea dx,[difference_msg]
call printstr

lea dx,difference
call printstr
mov ah, 4ch
int 21h
end begin``````

can u share ur multiplication part, pls. thx a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.