DOS assembly questions?
Hi,
First, is it OK to ask questions about assembly programming in DOS on
this list?
If so, here is my problem.
I am a real newb at assembly and am still learning the very basics. I have this bit of code. The way I understand it, this should print out "10". It does not. It prints some strange ASCII chars.
mov cx, 10
mov dx, cx
mov ah, 9
int 21
Where am I going wrong?
thank you for your help,
Michael
Quoted 9 lines · michael young
Hi,
First, is it OK to ask questions about assembly programming in DOS on
this list?
If so, here is my problem.
I am a real newb at assembly and am still learning the very basics. I have this bit of code. The way I understand it, this should print out "10".
It does not. It prints some strange ASCII chars.
Quoted 4 lines
mov cx, 10
mov dx, cx
mov ah, 9
int 21
ds:dx should be a pointer to a string "10$" for this to work. is this what you're doing? because your code does not show. you can find DOS calls here:
www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte1at0.htm
Hello,
Thanks to everyone for responding.
I'm sorry for not giving enough info.
What I want to do is starting at 10 (or some number).
1. print the number.
2. dec the number.
3. loop back to step 1.
4. when number reaches 0 print "All done" (or something). 5 end program
my code for this is:
BITS 16 ORG 0x0100
SEGMENT .text
START:
mov cx, 10
call myloop
myloop:
mov dx, cx
mov ah, 9
int 21H
dec cx
jnz myloop
mov dx, donemsg
mov ah, 9
int 21H
mov ah, 4CH
int 21H
SEGMENT .data
donemsg db "All done!", 13, 10, "$"
########### end of program ################
the output should be:
10
9
8
7
6
5
4
3
2
1
All done!
Yall say I can't print the numbers that way.
And sure enough that does not work.
How would yall suggest I go about this?
Also, I does loop the correct number of times but, it prints "All done!" after every iteration.
Can you tell me why that is?
Mr. Burt, don't worry about offending me.
Tell me what I need to hear.
A sharp knife cuts the quickest and hurts the least. Mr. Hyde, wonderful site. What does IIRC mean? Again, thank you to all of you for your responses and links.
Michael
BTW: i'm using nasm16 and I'm reading "Assembly Language Step-by-Step 2ed." by Jeff Duntemann.
I'm in DOS now but hope to move to LINUX assembly some day.
michael young wrote:
apparently, a common 'problem':
if ah:=9 and int 21 is supposed to send text,
the binary counter data can't appear visibly.
Quoted 1 line
[...]
Quoted 1 line
START:
mov cx, 10 => mov cx,"9"
Quoted 7 lines
call myloop
myloop:
mov dx, cx
mov ah, 9
int 21H
dec cx
cmp cx,"0"
jnz myloop => jc myloop
Quoted 1 line
mov dx, donemsg
[...]
best,
hp
Signature · 1 line
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml
Quoted 1 line
Quoted 1 line
xxxx -at- lxhp -dot- in-berlin -dot- de <<
Hi willy,
thank you for your response.
a question below.
Quoted 24 lines · willy meier
michael young wrote:
apparently, a common 'problem':
if ah:=9 and int 21 is supposed to send text, the binary counter data can't appear visibly.[...]Quoted 3 lines
START:
mov cx, 10 => mov cx,"9"
Quoted 9 lines
call myloop
myloop:
mov dx, cx
mov ah, 9
int 21H
dec cx
Quoted 3 lines
cmp cx,"0"jnz myloop => jc myloop
Here, wouldn't the 'dec' instruction set the 'ZF' if cx hit 0? where am I going wrong on this?
Quoted 11 lines
Quoted 5 lines
mov dx, donemsg
[...]best,
hp
michael
Hi
excuse me for the formatting of this mail I have to using windows when at the office.
As stated before ds:dx should point to the message you are trying to display
You should realize that the string "10" is composed of two ASCII characters which is 0x31 and 0x30.
This code
mov dx, 10
mov ah,9
int 21h
will display all characters at address ds:10 until it reaches '$'. when you decrement dx to 9 for the next loop it will display all the characters at
address ds:09 until it reaches '$'. What you need is to convert the contents of cx to a string '10'.
in the form
string db '10',10,13
you can use something like this
lea dx, string
mov ah,9
int 21h
mov ah,4ch
int 21h
string db 00
dummy db 10,13,'$'
and simply put the ASCII into the memory address of string.
Another problem that you will discover is that "0" uses only one byte, while "10" uses two bytes, which can
complicate your number_to_string function, but can still be done with patience. If you only want to convert 0 - 9 to
string you can simply add 0x30 to them and get an ASCII representation.
since you are all doing this under DOS you can check this by running the debug program.
I hope this helps,
,Fernan
michael young
<mhyoung@valdosta
.edu> To
Sent by: [email protected]
linux-assembly-ow cc
[email protected]
rg Subject
Re: DOS assembly questions?
10/22/03 02:05 AM
Hello,
Thanks to everyone for responding.
I'm sorry for not giving enough info.
What I want to do is starting at 10 (or some number).
1. print the number.
2. dec the number.
3. loop back to step 1.
4. when number reaches 0 print "All done" (or something). 5 end program
my code for this is:
BITS 16
ORG 0x0100
SEGMENT .text
START:
mov cx, 10
call myloop
myloop:
mov dx, cx
mov ah, 9
int 21H
dec cx
jnz myloop
mov dx, donemsg
mov ah, 9
int 21H
mov ah, 4CH
int 21H
SEGMENT .data
donemsg db "All done!", 13, 10, "$"
########### end of program ################
the output should be:
10
9
8
7
6
5
4
3
2
1
All done!
Yall say I can't print the numbers that way.
And sure enough that does not work.
How would yall suggest I go about this?
Also, I does loop the correct number of times but,
it prints "All done!" after every iteration.
Can you tell me why that is?
Mr. Burt, don't worry about offending me.
Tell me what I need to hear.
A sharp knife cuts the quickest and hurts the least. Mr. Hyde, wonderful site. What does IIRC mean? Again, thank you to all of you for your responses and links.
Michael
BTW: i'm using nasm16 and I'm reading "Assembly Language Step-by-Step 2ed." by Jeff Duntemann.
I'm in DOS now but hope to move to LINUX assembly some day.
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 32 lines · michael young
Hi willy,
thank you for your response.
a question below.Quoted 25 lines · willy meier
michael young wrote:
apparently, a common 'problem':
if ah:=9 and int 21 is supposed to send text,
the binary counter data can't appear visibly.[...]Quoted 3 lines
START:
mov cx, 10 => mov cx,"9"
Quoted 9 lines
call myloop
myloop:
mov dx, cx
mov ah, 9
int 21H
dec cx
Quoted 4 lines
Quoted 3 lines
cmp cx,"0"jnz myloop => jc myloop (<----- false, use 'jnc')
Here, wouldn't the 'dec' instruction set the 'ZF' if cx hit 0?
right but, binary value 0 would (if the rsp. terminal permits) just be the control code of <nul>. apparently (I know nothing about pc-dos specifica), the int-routine requires a character code in <dx> thus you either count and compare by chars codes or, add the byte value 48(decimal) to the counter value to sending the rsp char. much simplified, useable only for single digits (characters).
Quoted 1 line
where am I going wrong on this?
correction: the added opr should read 'jnc myloop'. loop terminates after cx was counted down to code("0")-1 (assuming that int 21 won't modify cx value)
did you forget the <ret> code after <call myloop>?
if no other code follows after <call myloop> you could either, use <jmp> or, delete the call instr, otherwise, in your example, 'myloop' would be run once more, before termination.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
mov dx, donemsg
[...]
best,
hp
Signature · 1 line
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml
Quoted 1 line
Quoted 1 line
hp -at- lxhp -dot- in-berlin -dot- de <<
Thank you.
I think I'm finally getting it.
I really appreciate everyone's help.
Michael
Quoted 160 lines · [email protected] wrote:
Hi
excuse me for the formatting of this mail I have to using windows when at the office.
As stated before ds:dx should point to the message you are trying to display
You should realize that the string "10" is composed of two ASCII characters which is0x31and0x30.This code
mov dx, 10
mov ah,9
int 21hwill display all characters at address ds:10 until it reaches '$'. when you decrement dx to 9 for the next loop it will display all the characters at
address ds:09 until it reaches '$'. What you need is to convert the contents of cx to a string '10'.
in the formstring db '10',10,13
you can use something like this
lea dx, string
mov ah,9
int 21h
mov ah,4ch
int 21hstring db 00
dummy db 10,13,'$'and simply put the ASCII into the memory address of string.
Another problem that you will discover is that "0" uses only one byte, while "10" uses two bytes, which can
complicate yournumber_to_stringfunction, but can still be done with patience. If you only want to convert 0 - 9 to
string you can simply add0x30to them and get an ASCII representation.since you are all doing this under DOS you can check this by running the debug program.
I hope this helps,
,Fernan
michael young
<mhyoung@valdosta
.edu> To
Sent by: [email protected]
linux-assembly-ow cc
[email protected]
rg Subject
Re: DOS assembly questions?10/22/03 02:05 AM
Hello,
Thanks to everyone for responding.
I'm sorry for not giving enough info.
What I want to do is starting at 10 (or some number).
1. print the number.
2. dec the number.
3. loop back to step 1.
4. when number reaches 0 print "All done" (or something). 5 end programmy code for this is:
BITS 16
ORG0x0100SEGMENT .text
START:
mov cx, 10
call myloopmyloop:
mov dx, cx
mov ah, 9
int 21H
dec cx
jnz myloop
mov dx, donemsg
mov ah, 9
int 21H
mov ah, 4CH
int 21HSEGMENT .data
donemsg db "All done!", 13, 10, "$"
########### end of program ################
the output should be:
10
9
8
7
6
5
4
3
2
1
All done!Yall say I can't print the numbers that way.
And sure enough that does not work.
How would yall suggest I go about this?
Also, I does loop the correct number of times but, it prints "All done!" after every iteration.
Can you tell me why that is?
Mr. Burt, don't worry about offending me.
Tell me what I need to hear.
A sharp knife cuts the quickest and hurts the least. Mr. Hyde, wonderful site. What does IIRC mean? Again, thank you to all of you for your responses and links.Michael
BTW: i'm using nasm16 and I'm reading "Assembly Language Step-by-Step 2ed." by Jeff Duntemann.
I'm in DOS now but hope to move to LINUX assembly some day.-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi willy,
I think, with help from you and everyone else
on this list, I'm understanding where I'm going
wrong. Many thanks for your help.
Michael
Quoted 93 lines · willy meier
Quoted 41 lines · michael young
Hi willy,
thank you for your response.
a question below.Quoted 33 lines · willy meier
michael young wrote:
apparently, a common 'problem':
if ah:=9 and int 21 is supposed to send text,
the binary counter data can't appear visibly.[...]Quoted 5 lines
START:
mov cx, 10 => mov cx,"9"
Quoted 11 lines
call myloop
myloop:
mov dx, cx
mov ah, 9
int 21H
dec cxQuoted 8 lines
Quoted 5 lines
cmp cx,"0"jnz myloop => jc myloop (<----- false, use 'jnc')
Here, wouldn't the 'dec' instruction set the 'ZF' if cx hit 0?
right but, binary value 0 would (if the rsp. terminal permits) just be the control code of <nul>. apparently (I know nothing about pc-dos specifica), the int-routine requires a character code in <dx> thus you either count and compare by chars codes or, add the byte value 48(decimal) to the counter value to sending the rsp char. much simplified, useable only for single digits (characters).
Quoted 3 lines
where am I going wrong on this?
correction: the added opr should read 'jnc myloop'. loop terminates after cx was counted down to code("0")-1 (assuming that int 21 won't modify cx value)
did you forget the <ret> code after <call myloop>?
if no other code follows after <call myloop> you could either, use <jmp> or, delete the call instr, otherwise, in your example, 'myloop' would be run once more, before termination.Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
mov dx, donemsg
[...]best,
hp