flat assembler
Message board for the users of flat assembler.

Index > DOS > Writing text Prints garbage, Need help

Author
Thread Post new topic Reply to topic
prana



Joined: 28 Aug 2003
Posts: 51
prana
Here is a tiny piece of code:

Code:

org  100h
a      db        '!','b','c'

mov     cl,3
loopcx:
mov     ah,2
mov     dl,[a]
int     21h
inc     [a]
loopnz  loopcx
mov     ax,4C00h
int     21h    

    


Intention is to print !bc sequentially. Prints garbage.

Another problem when I declare

Code:

a      db        'a','b','c'

    


The program compiles, but no output appears and it hangs.

Could someone throw some light?
Post 25 Sep 2003, 16:29
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7434
Location: Kraków, Poland
Tomasz Grysztar
Again that very common error: you are putting your data at the beginning of program and it gets executed then.
Post 25 Sep 2003, 16:38
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana
Sorry for the late reply.

Privalov, I couldn't get you! Could you please explain a little on my two questions?

Thanks.
Post 26 Sep 2003, 05:02
View user's profile Send private message Reply with quote
BiDark



Joined: 22 Jun 2003
Posts: 110
Location: .th
BiDark
just insert a jump to prevent the data to be executed like this.

Code:
  org 100h
  jmp @f 
  a db '!','b','c' 
@@:
  mov cl,3 
  loopcx: 
  mov ah,2 
  mov dl,[a] 
  int 21h 
  inc [a] 
  loopnz loopcx 
  mov ax,4C00h 
  int 21h
    


Or it would be better if you could declare the data at the end of code.


Last edited by BiDark on 26 Sep 2003, 05:38; edited 1 time in total
Post 26 Sep 2003, 05:36
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 492
Location: Norway
Tommy
You should declare data at the end of your program. Such as:
Code:
org 100h 

mov cl,3 
loopcx: 
mov ah,2 
mov dl,[a] 
int 21h 
inc [a] 
loopnz loopcx 
mov ax,4C00h 
int 21h

a db '!','b','c'     

You see? Else, you have to jump over the data:
Code:
org 100h

jmp data_end
a db '!','b','c' 
data_end:

...
    

Got it?

Regards,
Tommy
Post 26 Sep 2003, 05:37
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana
Thanks Tommy for answering.

Cut and pasted your code and the result is:

D:\fasmd\EXAMPLES>ex1
!"#
D:\fasmd\EXAMPLES>

Instead of !bc.

What's went wrong?
Post 26 Sep 2003, 06:09
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7434
Location: Kraków, Poland
Tomasz Grysztar
You are increasing the first byte of string at "a" label with
Code:
inc [a]    

instruction, and this is the only character you are displaying.
If you wanted to display all characters of your string, you have to increase address from which you are reading, for example:
Code:
mov bx,a
loopcx: 
mov ah,2 
mov dl,[bx] 
int 21h 
inc bx
loopnz loopcx    
Post 26 Sep 2003, 10:37
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana
Ok, I understand that the line

inc [a]

increments the ASCII content of 'a' and hence the result.

I've figured out the correct code with all of your help:

Code:

org 100h
  jmp @f
  a      db '!','b','c'
@@:
  mov    cl,3
  xor    ch,ch
  mov    bx,a
_loop:
  mov    dl,[bx]
  mov    ah,2
  int    21h
  inc    bx
  loopnz   _loop
  xor    ah,ah
  int    16h
  mov    ax,4C00h
  int    21h  

    



Thanks!
Post 26 Sep 2003, 10:46
View user's profile Send private message Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana
I've taken the following code from another thread and modified it a bit:

_____________________________________________
Code:
org 100h
  jmp @f
  _table      db '!','b','c'
  _msg        db 'Enter your name: ',24h
  _greet1     db 13,10,'Hello, ',24h
  _greet2     db '!!!',13,10,24h
  _buffer     db 80h,0
              rb 80h
  _lenmsg1    db 13,10,'You have entered '
  _lenmsg2    db 0
  _lenmsg3    db ' charcters.',24h
@@:

  mov    dx,_msg
  mov    ah,9
  int    21h

  mov     dx,_buffer
  mov     ah,0Ah
  int     21h

  mov     dl,[_buffer+1]
  add     dl,'0'
  mov     [_lenmsg2],dl

  mov     dx,_lenmsg1
  mov     ah,9
  int     21h

  mov    cl,[_buffer+1]
  xor    ch,ch
  mov    bx,_buffer+2

_loop:
  mov    dl,[bx]
  mov    ah,2
  int    21h
  inc    bx
  loopnz   _loop

  xor    ah,ah
  int    16h
  mov    ax,4C00h
  int    21h                       
    

______________________________________________________________

My question is that can I modify the following lines

Code:

  mov     dl,[_buffer+1]
  add     dl,'0'
  mov     [_lenmsg2],dl

    


in some better way? This takes a total of 261 b now.

Could you please help?
Post 26 Sep 2003, 11:33
View user's profile Send private message Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana
Could someone help me here on this?
Thanks.
Post 26 Sep 2003, 15:11
View user's profile Send private message Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
prana wrote:
My question is that can I modify the following lines

Code:
mov dl,[_buffer+1] 
add dl,'0' 
mov [_lenmsg2],dl     


in some better way? This takes a total of 261 b now.


What are you trying to achieve by this? If you want less size you can just move you variables to the end of the program and place these lines
Code:
_buffer db 80h,0 
rb 80h
    

at the very end.

_________________
Best regards,
Antoch Victor
Post 26 Sep 2003, 19:06
View user's profile Send private message Yahoo Messenger Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
In fact, here is version I tryed to make as short as possible:
Code:
        org 100h

        mov dx,_msg
        mov ah,9
        int 21h

        mov dx,_buffer
        mov ah,0Ah
        int 21h

        mov si,_buffer+1
        xor bx, bx
        mov bl,[si]
        mov word [si+bx+2], 240ah       ; place 0ah, '$' after 0dh in buffer
        add bl,'0'
        mov [_lenmsg2],bl

        mov dx,_lenmsg1
        mov ah,9
        int 21h

        mov ah,9
        mov dx,_buffer+2
        int 21h

        xor ah,ah
        int 16h

        ret

_msg     db 'Enter your name: ',24h
_lenmsg1 db 13,10,'You have entered '
_lenmsg2 db ' '
_lenmsg3 db ' characters: ',24h
_buffer  db 10,0
         rb 10h
    

_________________
Best regards,
Antoch Victor
Post 26 Sep 2003, 20:09
View user's profile Send private message Yahoo Messenger Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana
Thanks a lot Victor.

I am sorry, to answer so late.
Thanks again.
Post 27 Sep 2003, 01:55
View user's profile Send private message Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
Not at all, you're welcome.

_________________
Best regards,
Antoch Victor
Post 27 Sep 2003, 06:26
View user's profile Send private message Yahoo Messenger Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
What is the 'rb' in the code posted by wanderer??
Post 01 Oct 2003, 15:59
View user's profile Send private message Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
rb means reserve byte. The same as "db 10h dup(?)" in masm and tasm. To say the truth I just realized, that it's not necessary at all here and is probably thrown away by fasm.

_________________
Best regards,
Antoch Victor
Post 01 Oct 2003, 16:46
View user's profile Send private message Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.