hey all, im wondering how you declare a variable in a string. like say i want to declare a string saying "The number should be no less than X" and I want the X to be able to vary depending on what I have the variable for it at.

i tried putting this:

X_VALUE = 20
str1 BYTE "The number should be no less than ",X_VALUE,0

but i get some wierd symbol instead of my number so i know im doing it wrong.

8 Years
Discussion Span
Last Post by NotNull

Of course you get. X_VALUE is printed as ASCII-Character. You have to write a procedure to convert numbers to strings. Converting them to hex is quite simple. Just have a look out in the net.


You are wondering how you can have variable data in your string.
There are two methods,
that is, having a pointer (an offset) to a variable stored right after the string,
or have room for the variable itself
right after the string.
In either case your pointer
or the variable will be at an offset which is
the strings length
+ the offset of the string, which will
be the offset of the first byte of your
pointer or variable.

Here is some example code which
will leave room for a word after the

str db 'My String$',0,0
; the last two bytes leave room for
; a word

; to get the offset of the variable do:
MOV BX, offset str
ADD BX, 0Ah   ; add length of string
                      ; to offset of str in BX
MOV word ptr [BX], 1234h
                      ; Move the value 1234h
                      ; into the word at [BX]
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.