Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 18th, 2006, 4:00 PM   #21
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
After division, DX contains the remainder. In this case, DX holds the digit we just sliced off. Earlier I posted how the division works:
123 / 10
AX = 12
DX = 3

12 / 10
AX = 1
DX = 2

1 / 10
AX = 0
DX = 1
The only problem is that these values are bare. 3 is 3, 2 is 2, and 1 is 1. You want the ASCII representation of those numbers, where 3 is 51, 2 is 50, and 1 is 49. So to force that representation, you take the bare number and add '0', which has a value of 48.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old May 18th, 2006, 4:04 PM   #22
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
nicely explain Narue u have taught me alot in this thread alone and i can't think of anyway to thank you.................THANK YOU
kruptof is offline   Reply With Quote
Old May 19th, 2006, 11:27 AM   #23
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
hey Narue was just playing around with the code and when i change it to something like this: you don't get an ouput...... is like as if the save variable is blank?....................why is this.

Quote:
convert:
mov dx,0
div bx
add dx,'0'
mov [save+di],dl
test ax,ax
dec di;<----------this was before test
kruptof is offline   Reply With Quote
Old May 19th, 2006, 12:20 PM   #24
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
jnz relies on test to set the flags properly for the loop. dec also modifies flags, so if you move dec after test, jnz uses the result of dec as the loop condition. The reason it doesn't print anything is because save is initialized to DOS string terminators (the '$' character). When DI is 1, it's decremented to 0 and jnz is false, so the loop ends before filling in the first character of save. Since the first character is still '$', it's technically an empty string.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old May 19th, 2006, 1:23 PM   #25
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
oh ok...............that makes sense.............nicely explained again............your pretty advanced at this langauge do you do as a career Narue?
kruptof is offline   Reply With Quote
Old May 19th, 2006, 2:14 PM   #26
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
try playing around with this code even more but this time the DOS window just freezes when ever i run this program, here is the code:
Quote:
jmp start

save db 4 dup '$'

start:
mov di,0
jmp calc

calc:
mov ah,01
int 21h
mov [save+di],al
inc di
cmp al,13
jnz calc
add save,10

fini:
mov ah,4CH
mov al,00
kruptof is offline   Reply With Quote
Old May 19th, 2006, 3:32 PM   #27
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>jmp calc
There's no need for this unless you're jumping over something. Since calc is the next thing in the source, execution will fall through to it without your help.

>jnz calc
jne would make your intentions more obvious.

>add save,10
This doesn't make sense.

>mov al,00
You forgot the int 21h to terminate your program.

One big issue is the infinite loop you're going to cause by entering strings longer than two characters. Since you test the loop condition at the bottom, after you copy to save, entering something like 123 will actually cause '1', '2', 3', 10 to be written to memory. That erases the last '$', and 09h will just keep going until it finds a '$' somewhere else in memory. So you need to use a top testing loop to avoid writing the carriage return to save:
save db 4 dup '$'

start:
	mov	di,0

    calc:
	mov	ah,01
	int	21h
	cmp	al,13		; Test for CR first
	je	show
	mov	[save+di],al
	inc	di
	jmp	calc

    show:
	mov	ah,02h
	mov	dl,10
	int	21h

	; Display the result
	mov	ah,09h
	mov	dx,save
	int	21h

    fini:
	mov	ah,4CH
	mov	al,0
	int	21h
An alternative since a top testing loop uses an extra jump instruction, one at the top and one at the bottom, you can move that extra jump outside of the loop by using a bottom testing loop with a condition part:
save db 4 dup '$'

start:
	mov	di,0
	jmp	compare

    calc:
	mov	[save+di],al
	inc	di

    compare:
	mov	ah,01
	int	21h
	cmp	al,13
	jne	calc

    show:
	mov	ah,02h
	mov	dl,10
	int	21h

	; Display the result
	mov	ah,09h
	mov	dx,save
	int	21h

    fini:
	mov	ah,4CH
	mov	al,0
	int	21h
That's slightly more efficient, but it's also harder to follow.

>do you do as a career Narue?
I'm a professional programmer, yes. I tend to use assembly more than many programmers, but most of my work is in C and C++.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old May 19th, 2006, 3:39 PM   #28
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
okay i see my mistake................but what if i wanted to add a number to whats inside the save variable that's what the "add save,10" was for
kruptof is offline   Reply With Quote
Old May 19th, 2006, 7:07 PM   #29
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>but what if i wanted to add a number to whats inside the save variable
You access the memory just like you did when you copied the character in the first place:
add [save+index],value
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old May 20th, 2006, 5:49 AM   #30
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
i Hav tried to run the following code:
Quote:
save db 4 dup '$'
snum dw "Enter second$"

;start:
;mov bx,10
;mov ax,123
;mov di,0
;jmp input

;read:
;mov [save+di],al
;inc di
;jmp input

;input:
;mov ah,01
;int 21h
;cmp al,13
;jnz read

mov ah,09
mov dx,offset snum
int 21h

mov ah,04Ch
mov al,00
int 21h
but i keep an dialog boxes with an error on it (i have attached the image of this) do you know what this means Narue and if so can you please explain it to me
Attached Images
File Type: jpg MSDOS error.jpg (11.2 KB, 33 views)
kruptof is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC