[A83] Re: advanced stack-stuff
[Prev][Next][Index][Thread]
[A83] Re: advanced stack-stuff
Okay, here goes a shot:
current stack is displayed between ;/ and ;\
Start:
;/
SP = FFFFh
Stack = empty
;\
ld hl,5426h
push hl
;/
SP = FFFDh
Stack :
5426h
;\
call gamma; (PC is 9E00)
jr cont
gamma:
;/
SP = FFFBh
Stack :
9E03h (next instruction)
5426h
;\
pop hl ; hl is now 9E03h
;/
SP = FFFDh
Stack :
5426h
;\
push hl
push hl
;/
SP = FFF9h
Stack :
9E03h
9E03h
5426h
;\
ret ; returns to 9E03h to continue with execution, after that is a jump to cont
cont:
;/
SP = FFFBh
Stack :
9E03h
5426h
;\
pop de ; de is now 9E03h
;/
SP = FFFDh
Stack :
5426h
;\
pop bc ; bc is now 5426h
;/
SP = FFFFh
Stack = Empty
;\
ld (refvar),hl ; load 9E03h into mem address refvar... this was still in hl
.end
Note how we only use one ld to load a value into hl,
and we end up having that value in bc, and having some memory address in de,
only by using pop's, call's and ret's;
Note too that you can change the SP by using
ld (memvar),SP
ld SP,(memvar)
ld ix,SP
...
--Peter-Martijn
> Can somebody tell me what happens inside the stack and
> with the SP when I do some pushing/popping inside a call,
> then making a "ret", doing some more pushing, another ret,
> call XXXX, and so on??
> It doesn't have to be this example, but just give me what
> happens with this kinda stuff...
>
>
> SUCKER
>
>
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
>
References: