RSS Forums RSS
Please support our Assembly advertiser: Programming Forums
Views: 7321 | Replies: 0 | Thread Tools  Display Modes
Reply
Join Date: Sep 2005
Posts: 1
Reputation: Merc5 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Merc5 Merc5 is offline Offline
Newbie Poster

Need help with basic assembly calculator

  #1  
Sep 15th, 2005
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
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Assembly Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:22 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC