0
$\begingroup$

I found a picture of a 8086 family CPU.Where is the stack?I get it that the base and stack pointer are part of the general registers.

But shouldnt inside the ALU be both registers and a stack since the 8086 is both register and stack based CPU?

$\endgroup$

2 Answers 2

2
$\begingroup$

The stack is just ordinary memory. It is not part of the CPU. You just have one pointer to the start of the stack memory area, and one pointer to the current position of the stack in memory.

$\endgroup$
1
$\begingroup$

A stack in most CPUs is a range of memory addresses. In x86 basic usage, there is SP (later on, ESP, RSP, with extended width) which points to the stack top, and BP (ESP, EBP) which may point to the current function stack frame. (But since 80386 using BP is less necessary; 16-bit code can't use SP-based addressing but only BP-based. 32- and 64-bit code can use both.) On the other hand, you may program any user-level activity without stack at all; this will be annoying but possible.

There may be multiple stacks. In real, in a computer running a modern multitasking OS, each task (thread) has two stacks - user-level one (for the target activity) and kernel-level one (for system call handling).

Each stack is limited in space by two locations - minimal top and limit position (when SP points to it, this means the stack is empty). Stack bounds protection is nowadays usually made by guard pages that are always unmapped; but 8086 has no this mechanism so one should apply other means.

But: this is not true for 8087 (floating point coprocessor). It has 8 registers for floating-point values which are organized really as stack, so, with operations like "load from memory and push", "pop two values, multiply, push result" and so on. It's unclear why Intel pushed this design; a newer technique, SSE, don't organize register stack. So at 8087 scheme the register file can be called "stack" with full confidence.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.