944,111 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 12819
  • Assembly RSS
Sep 15th, 2005
0

Need help with basic assembly calculator

Expand Post »
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 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 :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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Merc5 is offline Offline
1 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: divide overflow???
Next Thread in Assembly Forum Timeline: Question: Where are good Assembly Compilers?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC