I ran into these two c macros and don't know how to convert them to masm. they are supposed to word align a pointer. Can someone with macro knowledge convert these for me?

#define Packet_ALIGNMENT sizeof(int)
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))

Posted on 2003-04-12 13:36:09 by rdaneel
for the Packet_ALIGNMENT:
masm32 provides SIZEOF too.

and the Packet_WORDALIGN:
x is the variable for the macro, packetalignment is already defined. the & is a binary and, the ~ is a binary negation. you can use the instruction not to do this binary negation. and for the binary and
Posted on 2003-04-12 13:43:56 by hartyl
does C define an int as a word?
Posted on 2003-04-12 13:48:10 by rdaneel
DWORD Signed integer I think.

PS: is the R.Daneel from R.Daneel Olivaw (Asimov) ?
Posted on 2003-04-12 15:53:11 by donkey
The size of an int in C is not standard. In old compilers like borland c (and other dos compilers) it's 16 bits long, in compilers for newer operating systems it's usually 32 bits. It's always a signed data type, though.
Posted on 2003-04-12 19:05:36 by Knightmare
Posted on 2003-04-12 23:51:36 by roticv

Have a look in the DIALOGS.INC file in the current version of MASM32 for a pair of macros that control alignment of memory.

They are very easy to modify to whatever alignment you require with the shift amount with SHR/SHL.

align_4 MACRO reg
add reg, 3
shr reg, 2
shl reg, 2

All you do is add the shift amount minus one and shift both ways the corect amount.


Posted on 2003-04-13 08:19:24 by hutch--
thanks guys. i still don't understand alignment very well but hutches suggestion seems to be working like it should.

donkey, Yes it is from Asimov. He is simply the god of sci-fi.
Posted on 2003-04-13 09:24:35 by rdaneel