If I compile the following code in nasm:
[bits 16]
push word 0x0101
nasm gives me the following output:
68 01 01
This instruction works fine when running in 16-bit mode.
Now, if I change to:
[bits 32]
push word 0x0101
nasm gives me the following output:
66 68 01 01
This does not work in 32-bit protected mode.
I know that pushing imm8 and imm32 works fine in protected-mode and I suspect that push imm16 would work fine if nasm outputted the same bytes as it is outputting in the 16-bits case.
Could somebody explain what I am missing? Thanks!
@harold After some investigation I found out that the push is actually working, but only 2 bytes are being pushed to the stack instead of 4. The program was breaking because I was incorrectly expecting 4 bytes when cleaning the stack. Thanks for that. – felipeek 1 min ago
Now, my question is: in 32-bit mode, push byte does push 4 bytes to the stack, using 3 bytes as padding (this is translated into x86's PUSH imm8 instruction). Similarly, push dword also pushes 4 bytes to the stack. Why push word would push only 2 bytes? It seems like a big inconsistency to me. Am I missing something?