Author Topic: terminating string output using '$'  (Read 12593 times)

nobody

  • Guest
terminating string output using '$'
« on: March 22, 2005, 07:14:14 AM »
i tried echoing the tempx's values (tempx's values are acquired from 0x0a loaded to ah) but the display seem to be erratic. its says printer out of paper and i/o error sumthin like that.. although i didnt use 0x05 for AH. i think its about the string not being terminated by '$'

i tried echoing it using the standard lea cmd

mov ah,0x09
lea dx,[tempx] <-- x is a number
int 0x21


how can i display it without all the display or pc being erratic??

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: terminating string output using '$'
« Reply #1 on: March 22, 2005, 11:11:53 AM »
After int 21h/0Ah returns, the number of bytes actually entered is in [tempx + 1]...

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

mov bl, [tempx + 1]
mov bh, 0
mov byte [tempx + 2 + bx], '$'

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

I don't recall whether the "count" includes the terminating carriage-return or not - adjust the "[tempx + 2 + bx]" so it comes out right :)

You can use "lea dx, [tempx + 2]" instead of the "mov"... but it's longer... Could use "movzx" to get the byte-sized count into the word-sized register, instead of "mov bh, 0", too...

There are other ways to print a string besides int 21h/9, too. The "write to file" int 21h/40h expects the "count" in cx, instead of the silly $-terminated string (bx wants the file handle to write to - 1 is stdout, 2 is stderr). Or you could display it one character at a time, watching for the terminating CR that int 21h/0Ah puts there...

mov si, tempx + 2
top:
lodsb
cmp al, 13
jz done
int 29h
jmp short top
done:

Pretty inefficient to call the OS for every character like that, though... The int 21h/40h is probably the most flexible...

Best,
Frank

nobody

  • Guest
Re: terminating string output using '$'
« Reply #2 on: March 23, 2005, 02:34:03 AM »
tnx frank.. im gonna try this to my code.. omg, u are so smart! youre a wiz!