Re: LZ: New method didnt work either


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

Re: LZ: New method didnt work either



On Fri, 27 Sep 1996, C.J. Oster wrote:


> >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???
> >-----------------------------
> 
> 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?
 
In the above scenario, everything is fine until you pop hl.
You can't just pop h.  Pops are 16 bit.  But assuming you
mean hl, here's what happens.


	push hl		; hl is on the stack
	call order	; the address of ld a,3 (xxx) 
xxx:	ld   a,3	; this is just to have something to refer to. 
order:
	pop hl		; the address of ld a,3 (xxx) is now in hl 
			; the stack still has the contents of hl
	ret		; the cpu tries to run the instruction at (hl)


Barry


References: