tags:

views:

122

answers:

4

Hi there,

Is the width of the stack 8 bit wide for IA32 architecture and for all types microprocessors/microcontrollers.

I am currently reading http://ozark.hendrix.edu/~burch/csbsju/cs/350/handouts/x86.html about assembly language. At the explanation of "call" it says that the stack pointer is being decreased by 4 and the program counter is push into the stack. Does this mean that the width of the stack buffer is of 8bit wide because the program counter is 32 bit long? I tried finding it in the intel IA32 architecture software development manual but can't seems to confirm it.

Thanks Sziang

+4  A: 

In the IA32 architecture, memory is addressed in bytes.

Hence, in order to put another 4 bytes on the stack, you need to shift your stack pointer by 4.

Anon.
I'm getting the feeling there's either a downvote bot or a bug somewhere... This seems to be happening a lot, suddenly.
Cogwheel - Matthew Orlando
+1, fwiw... (more characters)
Cogwheel - Matthew Orlando
Thank you anon and cogwheel, this is the answer that I am looking for. regardssziang
sziang
-1 not answer. The stack width under IA32 is 16 bit!
GJ
Correct (to put 4 bytes on the stack the stack pointer is changed by 4),but not answering the question.
Andreas
+2  A: 

It means that 8 bits is the smallest addressable unit of memory in the instruction set (a Byte). All memory addresses in IA32 represent a multiple of 8 bits of offset into RAM.

Cogwheel - Matthew Orlando
-1 the stack width under IA32 is 16 bit!
GJ
@GJ I didn't say anything about the stack width. The OP was wondering why pushing a 32 bit value moved the stack pointer by 4. The reason is because the stack pointer stores a memory address, and memory addresses are based on Bytes. My answer is not wrong, and in fact the asker accepted a nearly identical answer that came a few seconds before mine.
Cogwheel - Matthew Orlando
@Cogwheel but the question was: What is the width of a stack in an Intel IA32 architecture?
GJ
When you're answering a question you have two options: 1) narrowly interpret the question based on the title, ignoring all other context; 2) Read the entire post by the asker and try to figure out what high level concept they're trying to understand. We went with #2, and you down-voted us for it.
Cogwheel - Matthew Orlando
@Cogwheel: the reason why I have down voted is in the fact that the answers aren't right. I have expected that some on Stack Overflow nows hwat the program stack is. But this is probably another question for Stack Overflow!
GJ
@GJ: Again you seem to have completely missed the point... I was answering the question he wrote in the body: "Does this mean that the width of the stack buffer is of 8bit wide because the program counter is 32 bit long?"
Cogwheel - Matthew Orlando
+3  A: 

Operations that push values on "the stack" for an x86 CPU (e.g., operations involved ESP such as PUSH, CALL, etc.) all push in 4-byte increments. The effective width of the stack is 4 bytes/32 bits. If you are coding for an x64 CPU, it is 8 bytes wide, but you asked about IA32.

I have always had the stack pointer aligned on a 4 byte (DWORD) boundary. I don't know if you can DWORD-misalign the stack and have it work properly; if it does, you'll pay a serious performance penalty when accessing memory for pushes and pops (which is done very frequently in real code) because the real processor wants to read in small power-of-two size chunks.

Ira Baxter
From the Intel reference manual, PUSH instruction description: there isn't any instruction such as "push al". "push imm8" adjusts the stack by the size of the stack pointer: "The address-size attribute of the stack segment determines the stack pointer size (16, 32 or 64 bits) [page 4-320 Volume B Instruction Set Reference]". So if you running in 16 bit mode it will push 16 bits, but I don't consider that to be "IA32" mode at least not in the spirit of the question. (I haven't coded a 16 bit wide stack push since 1987).
Ira Baxter
Actually, 1 is a small power of two as well :-) And I'm amazed that you know the exact year you last coded a 16-bit push. But +1 for educating me. I didn't realise they were 32-bit pushes regardless of the operand size. Guess I've been out of the asm world for too long.
paxdiablo
Pretty easy to remember; that's the year I got my first Pentium chip and a real Unix box. No more 16 bit stuff.
Ira Baxter
+3  A: 

This is the first time I heard about "stack width".

push/pop/call/ret have a default width (which matches the processors operating mode). But the stack per se has no width. (Alignment is a totally different story.)

From the Intel docs (for push):

"In non-64-bit modes: if the address-size and operand-size attributes are 32,
the 32-bit ESP register (stack pointer) is decremented by 4.
If both attributes are 16, the 16-bit SP register (stack pointer)
is decremented by 2."

[...]

"In 64-bit mode, the instruction’s default operation size is 64 bits.
In a push, the 64-bit RSP register (stack pointer) is decremented by 8."

For manuals (which always have the last word) check: Intel Processor Manuals

Andreas