944,014 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 2620
  • Assembly RSS
Nov 26th, 2007
0

Sum of numbers will not display

Expand Post »
I believe the disp_sum (last) call is incorrect because the program will execute but the sum will not be displayed.
Project is due tomorrow (11/27) so prompt assistance will be greatly appreciated
Thanks in advance!


; A Simple Calculator that performs basic arithmetic (+ - * /)

.model small

.stack 256

CR equ 13d
LF equ 10d

.data

promptNum1 db 'Please Enter The First Number:', 0 ;string terminated by 0
promptNum2 db CR, LF,'Please Enter The Second Number:',0 ;string terminated by 0
sum db CR, LF, 'The sum Of The Two Numbers Is:', 0 ;string terminated by 0
num1 dw ?
num2 dw ?
.code

start:

mov ax, @data ;set ds register to point to data segment
mov ds, ax ;since you cannot assign a segment to ds directy
mov ax, offset promptNum1 ;store memory address of promptNum1 in ax

call display_str ;calls the display_str to display promptNum1 string
call read_input ;read first number entered by user

mov num1, ax ;store the number entered by user into num1 variable
mov ax, offset promptNum2 ;store memory address of promptNum2 into ax

call display_str ;calls the display_str to display promptNum2 string
call read_input ;read second number entered by user

mov num2, ax ;store the second number entered by user into num2 variable
mov ax, offset sum ;store memory address of sum into ax

call display_str ;calls the display_str to display sum string

mov ax, num1 ; ax = num1 ;move contents of num1 variable to the ax register
add ax, num2 ; ax = ax + num2 ;add contents of num2 variable to the existing contents of ax

call putn ; display sum ;call putn function to display the value of sum
mov ax, 4c00h
int 21h ; finished, back to dos

display_str: ;definition of display_str which displays string terminated by 0
push ax ;save contents of register ax
push bx ;save contents of register bx
push cx ;save contents of register cx
push dx ;save contents of register dx
mov bx, ax ;store address in bx (required for display)
mov al, byte ptr [bx] ;copy address of first character in string to al register

display_loop: cmp al, 0 ;while loop, while al != 0
je display_rest ;if last result was 0, then go to display_restore
call disp_char ;display character, one at a time, while al != 0
inc bx ;loop control, bx = bx + 1
mov al, byte ptr [bx] ;display next character in string
jmp display_loop ;go back to beginning of loop

display_rest:
pop dx ;restore register to beginning value
pop cx ;restore register to beginning value
pop bx ;restore register to beginning value
pop ax ;restore register to beginning value
ret


disp_char: ;display character stored in al, called by display_loop
push ax ;save contents of register ax
push bx ;save contents of register bx
push cx ;save contents of register cx
push dx ;save contents of register dx
mov dl, al ;move contents of al into bl (required for display)
mov ah, 2h ;call DOS display subprogram
int 21h ;interrupt to call subprogram
pop dx ;restore register to beginning value
pop cx ;restore register to beginning value
pop bx ;restore register to beginning value
pop ax ;restore register to beginning value
ret

read_input: ;read character into al
mov ah, 1h ;call DOS input subprogram
int 21h ;interrupt to call subprogram
ret


disp_sum ; display string terminated by 0
; dx contains address of string
mov dh, ah
mov ah, 2h
int 21h
ret


end start
Last edited by khalifah; Nov 26th, 2007 at 11:03 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khalifah is offline Offline
5 posts
since Nov 2007
Nov 27th, 2007
0

Re: Sum of numbers will not display

Actually, reading the forum rules and taking care to make sure that your post is presented in the best light (and not just dumped because you're in a hurry) is a good idea.
http://www.daniweb.com/forums/announcement125-3.html
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Nov 27th, 2007
0

Re: Sum of numbers will not display

I don't think it is dumped and I am not asking anyone to do my 'homework".
I have presented very well documented code, the last part of which probably needs minor correction.
Please advise if you are familiar with this language
Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khalifah is offline Offline
5 posts
since Nov 2007
Nov 27th, 2007
0

Re: Sum of numbers will not display

In disp_sum I am missing a : but changing that did not resolve the issue.
I think I am using the wrong registers in display_sum.
The add function stores the 'sum' in ax and I want to be able to output that to the screen.

mov ax, num1
add ax, num2
Last edited by khalifah; Nov 27th, 2007 at 8:57 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khalifah is offline Offline
5 posts
since Nov 2007
Nov 27th, 2007
0

Re: Sum of numbers will not display

one more error, the putn statement after the addition should say disp_sum.
This too does not fix the issue
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khalifah is offline Offline
5 posts
since Nov 2007
Nov 27th, 2007
0

Re: Sum of numbers will not display

Sure it's dumped.

Compare your mess with the nicely formatted code here.

But anyway, it's now past your deadline, so it's a moot point.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Nov 27th, 2007
0

Re: Sum of numbers will not display

I see what you are saying...
Do you want me to repost? The deadline is not till 1pm
Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khalifah is offline Offline
5 posts
since Nov 2007

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: char parameters
Next Thread in Assembly Forum Timeline: debugger code





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


Follow us on Twitter


© 2011 DaniWeb® LLC