flat assembler
Message board for the users of flat assembler.
Index
> DOS > Writing text Prints garbage, Need help |
Author |
|
Tomasz Grysztar 25 Sep 2003, 16:38
Again that very common error: you are putting your data at the beginning of program and it gets executed then.
|
|||
25 Sep 2003, 16:38 |
|
prana 26 Sep 2003, 05:02
Sorry for the late reply.
Privalov, I couldn't get you! Could you please explain a little on my two questions? Thanks. |
|||
26 Sep 2003, 05:02 |
|
BiDark 26 Sep 2003, 05:36
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 |
|||
26 Sep 2003, 05:36 |
|
Tommy 26 Sep 2003, 05:37
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 |
|||
26 Sep 2003, 05:37 |
|
prana 26 Sep 2003, 06:09
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? |
|||
26 Sep 2003, 06:09 |
|
Tomasz Grysztar 26 Sep 2003, 10:37
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 |
|||
26 Sep 2003, 10:37 |
|
prana 26 Sep 2003, 10:46
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! |
|||
26 Sep 2003, 10:46 |
|
prana 26 Sep 2003, 11:33
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? |
|||
26 Sep 2003, 11:33 |
|
prana 26 Sep 2003, 15:11
Could someone help me here on this?
Thanks. |
|||
26 Sep 2003, 15:11 |
|
wanderer 26 Sep 2003, 19:06
prana wrote: My question is that can I modify the following lines 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 |
|||
26 Sep 2003, 19:06 |
|
wanderer 26 Sep 2003, 20:09
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 |
|||
26 Sep 2003, 20:09 |
|
prana 27 Sep 2003, 01:55
Thanks a lot Victor.
I am sorry, to answer so late. Thanks again. |
|||
27 Sep 2003, 01:55 |
|
wanderer 27 Sep 2003, 06:26
Not at all, you're welcome.
_________________ Best regards, Antoch Victor |
|||
27 Sep 2003, 06:26 |
|
OzzY 01 Oct 2003, 15:59
What is the 'rb' in the code posted by wanderer??
|
|||
01 Oct 2003, 15:59 |
|
wanderer 01 Oct 2003, 16:46
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 |
|||
01 Oct 2003, 16:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.