Reputation: 198657
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.
Upvotes: 4
Views: 5768
Reputation: 18513
I prefer using the write
service (AH=0x40
):
AH=0x40
BX
is the file handle; use the value 1 to write to the same device (such as the screen) as service AH=9
CX
is the number of bytes to be written; the data is not "terminated" (neither by NUL nor by $
), so all values (from 0 to 255) can be writtenDS:DX
points to the data (in your case: the string) to be writtenAH=9
; If you use a 32-bit DOS extension: EDX
, of course)The service is actually intended for writing data to a file; however, it can also be used to write a "string" to the "output" by setting BX
to 1.
Upvotes: 3
Reputation: 1
You can use 02 service of INT 21H instead of 09 service.
Here is the sample.
mov dl, '$'
mov ah,02
int 21h
Upvotes: -1
Reputation: 73672
You can't use DOS's 0x09
service to display $
signs, you'll need to use 0x02
. See here.
Upvotes: 9
Reputation: 10554
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.
Upvotes: 0
Reputation: 5065
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)
Upvotes: 3
Reputation: 1673
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 \
Upvotes: -2