13

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?

  • 5
    Th 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. – TonyM Apr 23 at 18:56
  • 4
    The 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 Monica Apr 24 at 8:38
  • @JBentley To my endless frustration, we do things differently here at Retrocomputing. – wizzwizz4 Apr 25 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) – DmytroL Sep 14 at 14:31
35

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.

| improve this answer | |
  • 4
    Short and to the point. – another-dave Apr 24 at 11:28
  • @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. – Graham Nye Apr 26 at 14:12
26

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.

| improve this answer | |
  • 3
    Reset 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. – supercat Apr 23 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? – Raffzahn Apr 23 at 21:34
2

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.

| improve this answer | |
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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