Re: LZ: New method didnt work either


[Prev][Next][Index][Thread]

Re: LZ: New method didnt work either



C.J. Oster wrote:
> 
> >That's not totally correct. The way it really works is that when you
> >make a call, the PC (program counter) get's set to the address of the
> >new instruction you want to execute, and the next instruction (that the
> >PC would normally contain if there was no call) get's pushed on the
> >stack. You can push and pop within the routine, as long as when the PC
> >hits the *ret* op code, the stack pointer points at the address that our
> >*call* put on the stack. For example:
> >
> >This is incorrect:
> >-----------------------------
> >       PUSH H          ;H gets put on stack
> >       CALL ORDER      ;PC contents (next instruction) gets put on stack
> >       ...             ;more code
> >ORDER:
> >       POP H           ;H is address of next instruction (after routine ends)
> >       ...             ;more code
> >       RET             ;PC now contains what was H ???PROGRAM CRASH???
> >-----------------------------
> >
> >If I had put a pop after my *CALL ORDER* (as you suggest), it would have
> >never gotten there.
> >You could use the *EX (SP),HL* command to make this particular example
> >work, or you could increment the stack pointer (INC SP), pop h (POP H),
> >then decrement the stack pointer so it pointed to the correct address
> >(DEC SP). I think I've gotten this right... somebody let me know if I
> >made a mistake somewhere...
> >
> >Josh Franta
> 
> Ok, now I'm confused, I've done very little Z80 asm, but on a 486, I could
> always push a register like A, and then set the A regisster to something,
> call a dos interrupt, and then pop A.  This would set A back to what I had
> it set to when I pushed it.  If this is incorrect, and it will crash a
> TI-85, can someone explain to me how to push and pop varibles without a
> crash?  When you call, it DOES put the address of the instruction that
> you're calling on the stack, but when you 'RET' from the function, it DEC's
> the SP and the stack is esentially the same as it was before you made the
> call, right?
> 
>                                         C.J. Oster
> 
> "Remember, if it jamms, force it, and if it breaks, it needed replacement
> anyway."
> "A Smith & Wesson beats four aces"
> 
> ********************************************************************
> Unsolicited commercial e-mail to the poster of this message
> will be proofread at $70/hr, minimum charge $150.  Submission
> of such e-mail to this address will suffice as contractual assent
> to the said charging schedule.
> ********************************************************************
> 
> 


That's right, except you must pop and push register pairs(af instead of 
just a).  It's fine if push something before and pop it after the call.  
You just can't pop it off when you are in the routine.  There's something 
called LIFO, last in, first out.  That's what the stack works on.  When 
you call, it puts down the address you are at right now, not what you are 
calling.  Any help?


<pre>
-- 
Compliments of:
_-_-_-_-_-_-_-_
  Alan Bailey
  mailto:bailala@mw.sisna.com
  IRC:Abalone
  Web:http://www.mw.sisna.com/users/bailala/home.htm
</pre>


References: