***********
*Byte that data will be pushed into
*last filled byte of stack. Second byte to be popped
*Second to last byte
*....
*Second byte to stack. Second to last byte that will be popped.
*First byte of stack
***********
04
03
02
01
00
05
04
03
02
01
00
03
02
01
00
So as a visual example, with the gui functions of DCSB libs, when you create a window or text box, it gets pushed on, and you pop it off to remove it from the screen basically?I haven't used DCSB, but that sounds quite possible.
Ah ok. so i should probably get better at z80 before using stacks too much since i wont be doing much complex math until i start making games and whatnot hahaIt's not just for complex math. If I want to use a for a port or something, but need to get the value later, I can just store it on the stack. It's the easiest way to get it. It's also useful for transferring numbers that normally wouldn't be allowed. For example, assume you couldn't do ld hl,de. With a stack, you could push de and then pop dl. There are many uses for it, some are just more common than others.
___Stack___ | Main: call Routine MainReturn: pop hl ret Routine: push hl ret | ___Stack___ MainReturn | Main: call Routine MainReturn: pop hl ret Routine: push hl ret | ___Stack___ MainReturn HL | Main: call Routine MainReturn: pop hl ret Routine: push hl ret | ___Stack___ MainReturn HL |
Main:
call PushStuff
ret
PushStuff:
pop ix
;Do any pushing or popping you need here:
push hl
push bc
push de
;Then use this instead of a return:
jp (ix)
Doesn't destroying IX mess with the OS?
Okay, I'll be sure not to touch that. What exactly does the OS use IY for, anyway?
But if you mess with IY, you can do a ld IY, Flags, right? ???
But if you mess with IY, you can do a ld IY, Flags, right? ???I think so. I know there's an actual address. I'm sure you could do push iy \ pop hl bcall DispHL to find out.