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?
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.
Stack resides where the programmer tells.
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.
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
PUSH are effectively unavailable to the user until SP is set.