Hey all...

Does anyone have a solution to splitting words in a struct into two bytes? I'm trying to write a struct for strings to use when I am declaring them so that they are declared in pascal-style (length is first byte followed by the string... ie.. foo db 5, "Hello"


struc string
{
common
label .data byte
.size = $-.data

db .size, data
}

This works great for this, however I was wondering if there is any way I coudl extend this so that the initial string can be larger than 256 bytes. I've tried changing 'db' to 'du' (to create double-byte strings) however things link printf choke on them. What i need is

SSDDDDDDDDDDDDDDDDDD

Where SS is two bytes dedicated to the size, and the rest is the string... Basically what I need to do is find out how to define a struc that, if possible splits the value in .size into high/low bytes which I can use..

John
Posted on 2003-03-02 06:18:43 by coogle
You probably mean something like:


struc string [data]
{
common dw .size
.data db data
.size = $-.data
}
Posted on 2003-03-02 11:37:46 by Tomasz Grysztar
struc string
{
common dw .size
.data db data
.size = $-.data
}


Won't that define:

myvar.size dw 5
myvar.data db "Hello"

Instead of:

myvar db 0,5,"Hello"

John
Posted on 2003-03-02 19:56:28 by coogle
Why do you need "db 0,5"? "dw 5" is the same as "db 5,0" and this is very handy for most purposes.
But if you really want it to be big-endian, just replace "dw .size" with "db .size shr 8,.size and 0FFh".
Posted on 2003-03-03 04:11:22 by Tomasz Grysztar