Z80 stack pointer

Discussion in 'Programmer's Corner' started by Dr.Wily, Mar 27, 2010.

  1. Dr.Wily

    Thread Starter New Member

    Mar 27, 2010
    1
    0
    I am having problems using the stack pointer on the Z80. Here is basically what I am trying to do.

    LD SP, 27FFh
    LD HL, ABCD
    PUSH HL
    HLT

    I look at address 27FFh and neither CDh or ABh is there. I also look at address 27FEh and it is not there. The memory logic is working because I can do this:

    LD HL, 27FFh
    LD (HL), AB
    HLT

    The value will be there. Any suggestions?
     
  2. topherCantrell

    New Member

    Aug 27, 2011
    1
    0
    On the Z80 PUSH instruction the stack pointer is decremented 2 places first. Then the value is stored where the pointer points. On a POP the value is read from memory and the stack pointer is then incremented 2 places. Your values are at 27FD and 27FE.
     
Loading...