tags:

views:

275

answers:

3

For example, for a 8-bit CPU, the stack size is expected to be 8-bit wide, and 16-bit CPU vs 16-bit stack width, and 32-bit, 64-bit CPU, and so on. Is it true for all architectures?

+2  A: 

A CPU has a data bus and a address bus. The can have the same width, but they often aren't.

The stack pointer is a pointer to memory, so its often as wide as the address bus, unless there is some (weird/obscure) conversion used internally. The instruction pointer (points to the current instruction) is also a pointer to memory and as such as wide as the stack pointer.

Other registers mostly deal with data, and as such have the same dimensions as the data bus. But as usual, there are exceptions.

To take an old example. The 6502. A 8 bit cpu (8 bit databus, 16 bit addressbus). It has the (more or less) general purpose registers X and Y, and the "accumulator" called A. All 8 bit registers. There was a stack pointer and a instruction pointer, both 16 bits.

The 8086, has an 16 bit databus and a 20 bit addressbus. The general registers where 8 (and 16 bit). The instruction pointer and stackpointer where 16 bit, but used segment registers (also 16 bit) to get the full 20 bit address.

Gamecat
+4  A: 

8-bit CPU, the stack size would expect to be 8-bit width

You might expect that, but you would be wrong. The basic use of the stack is to store & retrieve return addresses, and on 8-bit processors these are actually 16-bit values. For example the Z80 instruction:

PUSH HL

pushes a 16-bit value (the contents of the two 8-bit registers, H and L) onto the stack. There is no Z80 instruction which pushes an 8-bit value.

anon
A: 

The stack is really just a concept, and "stack width" doesn't really mean anything.

Presumably, you mean the width of the stack elements, but you can typically store arbitrary sized values on any stack (with some padding or alignment), regardless of the size of the architecture's bus width or register size.

Note that the terms 8-bit, 16-bit etc are a little arbitrary, and aren't really tight definitions, so this complicates any attempted definition of "width".

Paul Biggar