dollar-terminated strings
Question
In my assembly language class, our first assignment was to write a program to print out a simple dollar-terminated string in DOS. It looked something like this:
BITS 32
global _main
section .data
msg db "Hello, world!", 13, 10, ’$’
section .text
_main:
mov ah, 9
mov edx, msg
int 21h
ret
As I understand it, the $ sign serves to terminate the sting like null does in C. But what do I do if I want to put a dollar sign in the string (like I want to print out "it costs $30")? This seems like a simple question, but my professor didn't know the answer and I don't seem to find it using a google search.
Solution
You can't use DOS's 0x09
service to display $
signs, you'll need to use 0x02
. See here.
OTHER TIPS
Or make your own print_string to print a NULL-terminated string using the undocumented INT 29h (print character in AL).
; ds:si = address of string to print
print_string:
lodsb ; load next character from ds:si
or al, al ; test for NULL-character
jz .end_of_string ; end of string encountered, return.
int 29h ; print character in AL on screen
jmp print_string ; print next character
.end_of_string:
ret ; return to callers cs:ip
(Assuming you are using NASM)
Um. You could write assembly that would taken into account for escaped $
, e.g. \$
?
But then your \
becomes a special symbol too, and you need to use \\
to print a \
One way is to find the call that prints a single character. You can print any character with that. Break the string up and print "it costs ", then the '$', and finally, "30". More work, but it gets the job done.
You can use 02 service of INT 21H instead of 09 service.
Here is the sample.
mov dl, '$'
mov ah,02
int 21h
Try '$$', '\044' (octal) or '\x24' (hex)