Hi folks,

I have a question concerning the push-directive.
What I want to do is to directly push an integer (2 Bytes) onto the stack.

Is http://ref.x86asm.net/coder32.html#x68 to be understood that on a 32bit processor, this cannot be accomplished since it will always push 32 bits? Do I thus always have to use a register to store the value in first or push the two bytes consecutively (via opcode 6A)?

Or am I completely mistaken here?

Thanks alot,
Posted on 2009-09-06 06:39:49 by Claus von der Burchard
If the cpu is working in 16bit mode, push 16-bit values as much as your heart desires.

If you're in 32bit mode, (generally) don't - not even as two single-byte pushes. 32bit operating systems tend not to like the stack being misaligned :)
Posted on 2009-09-06 06:57:17 by f0dder
A minor clarification: you CAN push 1-byte or 2-byte immediate values on the stack in either mode - they will be sign-extended automatically.

So, you can either push a 1-byte immediate value, 2-byte value - these will get sign extended, 4-byte value, or a register. Pushing a register requires its size to be matched. So pushing a 1-byte register (like al) is generally bad. BUT you can push a 4-byte register (like eax) in 16-bit mode - this will effectively act like pushing 2 16-bit values.

What I want to do is to directly push an integer (2 Bytes) onto the stack.

You can do "push 02f0" or something like that - it will be sign-extended to 4 bytes and pushed. But you can't do "push ax" as this will push a 16-bit value and misalign the stack which means trouble on most OSes.
Posted on 2009-09-06 11:27:49 by ti_mo_n
Alright, thanks alot.

I missed the important-most piece of information given in http://msdn.microsoft.com/en-us/library/984x0h58%28VS.71%29.aspx (on calling conventions):
All arguments are widened to 32 bits when they are passed.

I had this API whose declaration spoke of 2-byte-integer, and since I didn't have that information, I thought I'd have to actually push 16 bits.

Again, thank you.
Posted on 2009-09-06 11:48:49 by Claus von der Burchard