Having trouble trying to search for this in the data sheet, just have seen how big it is and how it handles stack pointers. Would anyone mind helping me out where the "Stack" start on an Intel 8080?
-
5Th stack can be anywhere in the 64 KB address space and grow to any amount of the 64 KB address space. Software first loads the stack pointer with an initial address of the programmer's choice.– TonyMCommented Apr 23, 2020 at 18:56
-
4The 8080 stack doesn't remain in a confined space like the 6502 stack. It can potentially romp all across memory, causing a condition which StackExchange's original site was named after. In fact, that's one lazy way to do a memory clear, set the SP to the space, and "push like hell"...– Harper - Reinstate MonicaCommented Apr 24, 2020 at 8:38
-
@JBentley To my endless frustration, we do things differently here at Retrocomputing.– wizzwizz4 ♦Commented Apr 25, 2020 at 21:48
-
Some demo / game programmers of the era even temporarily moved the stack pointer to the video RAM address space to speed up blitting (one could transfer data in 16-bit words by hard-coding source addresses and using an unrolled loop like LHLD <source addr> followed by PUSH H)– DmytroLCommented Sep 14, 2020 at 14:31
4 Answers
The stack starts wherever you as the programmer choose to initialize it to. Note that the stack grows downwards (i.e. towards lower memory addresses) so you would normally initialize the stack pointer to point to the top of a free area of RAM.
-
5
-
@another-dave Thanks. It sounds as though OP has access to low-level documentation in the data sheet but, as is too often the case, it lacks context on how you might use a feature. Commented Apr 26, 2020 at 14:12
-
Normally you would initialise it to point to an address one above the area where you want the stack to start. The current value of the stack pointer points to the most recent LSB (of a register pair) pushed on the stack and the next PSH will put the MSB in (SP-1) and the LSB in (SP-2).– cjsCommented Jul 21, 2023 at 12:52
Would anyone mind helping me out where the "Stack" start on an Intel 8080?
After Reset content of the stackpointer is undefined.
Keep in mind, these are early 8 bit machines. There is no huge hardware and microcode that puts every part into a well defined state. For the 8080 the only thing guaranteed is that the PC will be reset to zero and execution starts from there (*1). Everything else has to be initialized by software (Boot code).
*1 - Reset is effectively just a clear input for the PC.
-
3Reset isn't just a clear input for the PC. It also needs to block execution of any instruction in progress. Otherwise, if e.g. RESET were asserted between the fetch of an "STA" instruction and the fetch of its operands, and the instruction at address 0000 was a JMP [ocode 0C3h], the STA instruction would write to address 0C3C3h.– supercatCommented Apr 23, 2020 at 20:12
-
14@supercat That's why the specifier 'effectively' has been used. After all, this is not supposed to be a course in CPU design, but helping the OP on a rather high abstraction leven, isn't it?– RaffzahnCommented Apr 23, 2020 at 21:34
Stack resides where the programmer tells.
LXI SP,0FFFFh
or
LXI H,0FFFFh
SPHL
are the most commonly used construction to tell CPU where the stack should reside. So the main program has to set SP itself, and the best practise is to do it at the same beginning of execution.
The typical sequence is:
ORG 0
DI
LXI SP, STACK
The DI instruction disables interrupt, which is effectively the same as CALL, i.e. it writes the return address on the stack. So DI is often the very first instruction, just to be sure that interrupt does not execute prior the stack pointer is valid.
-
Note that this sets the top of the stack to $FFFE: the current value of the stack pointer points to the most recent LSB (of a register pair) pushed on the stack and the next
PSH
will put the MSB in (SP-1) and the LSB in (SP-2). If you wanted the stack to start at the top of memory, you need to load it with $0000.– cjsCommented Jul 21, 2023 at 12:50
An example: the source code for a simple 8080 Monitor is here (PDF format, code starts on page 8 of 41).
After several repeats of MVI A, ... / OUT ...
to set up hardware, we hit the magic line:
LXI SP,STACK ; SETUP THE STACK AT 0EFF0H
So the user has to initialize the stack in the right place, as Graham Nye said.
The comment in the very next line explains why this is so important:
; Have a Stack, so we can use CALL
CALL
and PUSH
are effectively unavailable to the user until SP is set.