All of lore.kernel.org
 help / color / mirror / Atom feed
* DOS assembly questions?
@ 2003-10-20 23:46 michael young
  2003-10-21  6:05 ` Fekete Gabor
  2003-10-21 18:05 ` michael young
  0 siblings, 2 replies; 9+ messages in thread
From: michael young @ 2003-10-20 23:46 UTC (permalink / raw)
  To: linux-assembly

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-20 23:46 DOS assembly questions? michael young
@ 2003-10-21  6:05 ` Fekete Gabor
  2003-10-21 18:05 ` michael young
  1 sibling, 0 replies; 9+ messages in thread
From: Fekete Gabor @ 2003-10-21  6:05 UTC (permalink / raw)
  Cc: linux-assembly



On Mon, 20 Oct 2003, michael young wrote:

> 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

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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-20 23:46 DOS assembly questions? michael young
  2003-10-21  6:05 ` Fekete Gabor
@ 2003-10-21 18:05 ` michael young
  2003-10-22  6:07   ` willy meier
  2003-10-24  5:22   ` FernanBolando
  1 sibling, 2 replies; 9+ messages in thread
From: michael young @ 2003-10-21 18:05 UTC (permalink / raw)
  To: linux-assembly

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.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-21 18:05 ` michael young
@ 2003-10-22  6:07   ` willy meier
  2003-10-23 17:00     ` michael young
  2003-10-24  5:22   ` FernanBolando
  1 sibling, 1 reply; 9+ messages in thread
From: willy meier @ 2003-10-22  6:07 UTC (permalink / raw)
  To: michael young, linux-assembly; +Cc: linux-assembly

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.
> 
	[...]
> START:
   mov cx, 10	=>	mov cx,"9"
>   call myloop
> 
> myloop:
>   mov dx, cx
>   mov ah, 9
>   int 21H
>   dec cx
			cmp cx,"0"
   jnz myloop	=>	jc myloop
>   mov dx, donemsg
	[...]

best,
	hp

-- 
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml
  >> xxxx -at- lxhp -dot- in-berlin -dot- de <<

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-22  6:07   ` willy meier
@ 2003-10-23 17:00     ` michael young
  2003-10-24 17:12       ` willy meier
  0 siblings, 1 reply; 9+ messages in thread
From: michael young @ 2003-10-23 17:00 UTC (permalink / raw)
  Cc: linux-assembly


Hi willy,
thank you for your response.
a question below.


willy meier wrote:

>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.
>  
>
>	[...]
>  
>
>>START:
>>    
>>
>   mov cx, 10	=>	mov cx,"9"
>  
>
>>  call myloop
>>
>>myloop:
>>  mov dx, cx
>>  mov ah, 9
>>  int 21H
>>  dec cx
>>    
>>
>			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?

>  
>
>>  mov dx, donemsg
>>    
>>
>	[...]
>
>best,
>	hp
>  
>
michael



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-21 18:05 ` michael young
  2003-10-22  6:07   ` willy meier
@ 2003-10-24  5:22   ` FernanBolando
  2003-10-28 22:11     ` michael young
  1 sibling, 1 reply; 9+ messages in thread
From: FernanBolando @ 2003-10-24  5:22 UTC (permalink / raw)
  To: michael young; +Cc: linux-assembly, linux-assembly-owner





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:                  linux-assembly@vger.kernel.org      
             linux-assembly-ow                                          cc 
             ner@vger.kernel.o                                             
             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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-23 17:00     ` michael young
@ 2003-10-24 17:12       ` willy meier
  2003-10-28 22:19         ` michael young
  0 siblings, 1 reply; 9+ messages in thread
From: willy meier @ 2003-10-24 17:12 UTC (permalink / raw)
  To: michael young; +Cc: linux-assembly, linux-assembly

michael young wrote:
> 
> Hi willy,
> thank you for your response.
> a question below.
> 
> willy meier wrote:
> 
> >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.
> >
> >
> >       [...]
> >
> >
> >>START:
> >>
> >>
> >   mov cx, 10  =>      mov cx,"9"
> >
> >
> >>  call myloop
> >>
> >>myloop:
> >>  mov dx, cx
> >>  mov ah, 9
> >>  int 21H
> >>  dec cx
> >>
> >>
> >                       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).

> 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.

> 
> >
> >
> >>  mov dx, donemsg
> >>
> >>
> >       [...]

best,
       hp

-- 
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml
  >> hp -at- lxhp -dot- in-berlin -dot- de <<

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-24  5:22   ` FernanBolando
@ 2003-10-28 22:11     ` michael young
  0 siblings, 0 replies; 9+ messages in thread
From: michael young @ 2003-10-28 22:11 UTC (permalink / raw)
  To: FernanBolando; +Cc: linux-assembly, linux-assembly-owner

Thank you.
I think I'm finally getting it.
I really appreciate everyone's help.

Michael

FernanBolando@astec-power.com 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 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:                  linux-assembly@vger.kernel.org      
>             linux-assembly-ow                                          cc 
>             ner@vger.kernel.o                                             
>             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 majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>
>  
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DOS assembly questions?
  2003-10-24 17:12       ` willy meier
@ 2003-10-28 22:19         ` michael young
  0 siblings, 0 replies; 9+ messages in thread
From: michael young @ 2003-10-28 22:19 UTC (permalink / raw)
  To: willy meier; +Cc: linux-assembly, linux-assembly

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



willy meier wrote:

>michael young wrote:
>  
>
>>Hi willy,
>>thank you for your response.
>>a question below.
>>
>>willy meier wrote:
>>
>>    
>>
>>>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.
>>>
>>>
>>>      [...]
>>>
>>>
>>>      
>>>
>>>>START:
>>>>
>>>>
>>>>        
>>>>
>>>  mov cx, 10  =>      mov cx,"9"
>>>
>>>
>>>      
>>>
>>>> call myloop
>>>>
>>>>myloop:
>>>> mov dx, cx
>>>> mov ah, 9
>>>> int 21H
>>>> dec cx
>>>>
>>>>
>>>>        
>>>>
>>>                      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).
>
>  
>
>>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.
>
>  
>
>>>      
>>>
>>>> mov dx, donemsg
>>>>
>>>>
>>>>        
>>>>
>>>      [...]
>>>      
>>>
>
>best,
>       hp
>
>  
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-10-28 22:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-20 23:46 DOS assembly questions? michael young
2003-10-21  6:05 ` Fekete Gabor
2003-10-21 18:05 ` michael young
2003-10-22  6:07   ` willy meier
2003-10-23 17:00     ` michael young
2003-10-24 17:12       ` willy meier
2003-10-28 22:19         ` michael young
2003-10-24  5:22   ` FernanBolando
2003-10-28 22:11     ` michael young

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.