Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 322
Tim Green Avatar asked Apr 06 '10 16:04

Tim Green


People also ask

What does push do x86?

The push instruction places its operand onto the top of the hardware supported stack in memory. Specifically, push first decrements ESP by 4, then places its operand into the contents of the 32-bit location at address [ESP].

What does the push instruction do?

The PUSH instruction saves the current PRINT, USING, or ACONTROL status in push-down storage on a last-in, first-out basis. You restore this PRINT, USING, or ACONTROL status later, also on a last-in, first-out basis, by using a POP instruction.

How many registers does IA32 have?

The IA-32 processors have four 32-bits index and pointer registers (ESI, EDI, ESP and EBP). These registers can also be used as four 16-bits registers (SI, DI, SP and EP). Usually ESI and EDI are used as regular data registers. But when using the string instructions they have special functions.

What is DUP in assembly language?

means no particular value, uninitialized. DUP means duplicate. So you get 100h bytes that are uninitialized.


1 Answers

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.

like image 156
Yuliy Avatar answered Jan 02 '23 05:01

Yuliy