Hi
New to the forum! I REALLY need help with a simple assembly calculator. Basically, the program is supposed to display a menu, obtain two numbers from the user (in the rang :confused: e of 0 - 9) and depending on the choice made in the menu add or subtract the two values to or from each other. The result must then be displayed :confused: :eek:
My problem is that I don't know how to do the addition. Can someone please take a look and help me? :(
.model small
.stack
.code
Start:
mov dx, OFFSET welcome
mov ax, SEG welcome
mov ds, ax
mov ah, 9
int 21h
mov dx, OFFSET menu1
mov ax, SEG menu1
mov ds, ax
mov ah, 9
int 21h
mov dx, OFFSET menu2
mov ax, SEG menu2
mov ds, ax
mov ah, 9
int 21h
mov dx, OFFSET menu3
mov ax, SEG menu3
mov ds, ax
mov ah, 9
int 21h
xor ah, ah
int 16h
mov bl, al
mov dl, al
mov ah, 02h
int 21h
cmp bl, 'a'
jz Read_First
cmp bl, 'A'
jz Read_First
cmp bl, 's'
jz Read_First
cmp bl, 'S'
jz Read_First
cmp bl, 'q'
jz Quit
cmp bl, 'Q'
jz Quit
Read_First:
call Prompt
call Readchar
mov cl, al
sub cl, 30h
cmp cl, 9h
ja printIllegal
cmp cl, 0h
jb printIllegal
call Read_Second
Read_Second:
mov dx, OFFSET prompt2
mov ax, SEG prompt2
mov ds, ax
mov ah, 9
int 21h
call Readchar
mov dl, al
sub dl, 30h
cmp dl, 9h
ja printIllegal
cmp dl, 0h
jb printIllegal
call Addition
Prompt:
mov dx, OFFSET prompt1
mov ax, SEG prompt1
mov ds, ax
mov ah, 9
int 21h
ret
printIllegal:
mov dx, OFFSET invalid
mov ax, SEG invalid
mov ds, ax
mov ah, 9
int 21h
call Read_First
Addition:
add ax, cl
add ax, dl
mov dx, OFFSET addMsg
mov ax, SEG addMsg
mov ds, ax
mov ah, 9
int 21h
mov ah, 2h
int 21h
Readchar:
mov ah, 1h
int 21h
ret
print_Char:
mov ah, 2h
int 21h
ret
Quit:
mov ax, 4c00h
int 21h
.data
LF equ 10d
CR equ 13d
welcome db "Welcome to my calculator", LF, CR, LF, CR, "$"
menu1 db "A: Addition",LF, CR, "$"
menu2 db "S: Subtraction", LF, CR, "$"
menu3 db "Q: Quit", LF, CR, "$"
prompt1 db LF, CR, "Please enter the first number: $"
prompt2 db LF, CR,"Please enter the second number: $"
invalid db LF, CR,"Invalid number$"
addMsg db LF, CR, "Addition of two numbers equal to: $"
subMsg db LF, CR, "Subtraction of two numbers equal to: $"
end Start