Why is it not possible to push a byte onto a stack on Pentium IA-32?

12,768

Solution 1

It'll make the stack pointer not able to do its job in some cases. for instance, lets say you had a function which pushed a byte onto the stack and then calls another function. The call will end up trying to write a misaligned return address onto the stack, resulting in an error.

Solution 2

what you want to do is use the bit rotation opcodes to rotate through each 32-bit memory location, placing 8 bits at a time into the register until you have rotated back to the starting bit positions. now you should have 4 8-bit quantities lined up side by side in your 32 bit register. now push that onto the stack and you're done.

Share:
12,768
Tim Green
Author by

Tim Green

Updated on June 13, 2022

Comments

  • Tim Green
    Tim Green almost 2 years

    I've come to learn that you cannot push a byte directly onto the Intel Pentium's stack, can anyone explain this to me please?

    The reason that I've been given is because the esp register is word-addressable (or, that is the assumption in our model) and it must be an "even address". I would have assumed decrementing the value of some 32-bit binary number wouldn't mess with the alignment of the register, but apparently I don't understand enough.

    I have tried some NASM tests and come up that if I declare a variable (bite db 123) and push it on to the stack, esp is decremented by 4 (indicating that it pushed 32-bits?). But, "push byte bite" (sorry for my choice of variable names) will result in a kind error:

    test.asm:10: error: Unsupported non-32-bit ELF relocation

    Any words of wisdom would be greatly appreciated during this troubled time. I am first year undergraduate so sorry for my naivety in any of this.

  • Tim Green
    Tim Green about 14 years
    Sorry, that doesn't make much sense to me.
  • Tim Green
    Tim Green about 14 years
    While this does make sense, Yully's answer explains it from the bottom up. Thanks anyway :)
  • Christoph Fischer
    Christoph Fischer about 2 years
    The main registers on x86 Systems (which IA-32 is) have enough space for 4 Bytes. You can only write into the lower 2 Bytes though. So you once you have written those you can rotate the register (ROL EAX, 16) so the written Bytes are in the top 2 Byte-sections of the register. Now you can write into the lower 2 Bytes again. When you push that register you have 4 Bytes back to back on the Stack.