0 Members and 2 Guests are viewing this topic.
Label1: call label2 ret ; Let's call this one "ret%" This will go to where I want!Label2 ret ; I want this "ret" to go to the same 'place' as "ret%".
Label1:Call Label2(......) ;[1]Label2:Call Label3ret ;[2] Will take it back to [1].Label3:Call Label4ret ;[3] Will take it back to [2].Label4:Call Label5ret ;[4] Will take it back to [3].Label5:ret ;[5] Will take it back to [4].
Yeah, iirc, the last address is stored on the stack. Try a pop into hl and then go to that address.
Label1: Call Label2 (...)Label2: Call Label3 ret ; <-- isn't neccarery, since it will nver get executed, right?Label3: POP HL ret ;<-- will go to label 1?
Try a pop into hl and then go to that address.
Label1:push Label2retLabel2:ret
9D95h: Label1:9D95h: call Label2 // 1. Pushes 9D97 to the stack, loads 9D98 into PC9D97h: ret // 5. This executes.9D98h: Label2:9D98h: call Label3 // 2. This loads 9D9B onto the stack (the stack at this point: 9D9B, 9D97) and loads 9D9C into PC9D9Bh: ret9D9Ch: Label3:9D9Dh: pop hl // 3. This removes the last stack entry (the stack at this point: 9D97)9D9Eh: ret // 4. This does the equivalent of POP PC (PC now equals 9D97)
That looks like it will work at first glance, but I don't konw why it isn't. This is how calls work:
Try this as a completely new program:Code:Label1:push Label2retLabel2:retThis should exit the program because you are pushing the location of Label2 onto the stack, and then returning to it. Not sure, though. If that doesn't work, just push two zeros onto the stack, and run it with a ret. That should reset your calc, so beware.
ret // 4. This does the equivalent of POP PC (PC now equals 9D97)
ret IS pop pc.pop hl pops hl.
push hlpush bcpop hlpop bc
Label1:push Label1jr Label2
POP HL \ ret should work, Jerros. Maybe the fault is elsewhere? Do you mind posting the code fragment involved?
Label1:(...) CALL Label2(...) ; <-- must get executed after the RET*Label2:(...) CALL label3(...) ; <-- A normal Ret in Label 3 will cause this to be executed. I don't want that :P.retLabel3: b_call _GetCSC CP skDel JP Z, Quit JR Label3Quit: ret ; and I want this RET* to go to Label1, NOT 2.
Err...ret \ ret would pop pc twice, but the first time you pop pc, the next line will not execute, because PC will be elsewhere. Pop is not exclusive to variables, they are all on the stack together. For instance:Code: [Select]push hlpush bcpop hlpop bcThis will swap the values of hl and bc. Therefore, if (9D95:) call xxxx pushes PC to the stack and loads xxxx into pc, the stack looks like this:9D95Then, if you pop hl, you can no longer return to that location unless you push it back. Look at this:Code: [Select]Label1:push Label1jr Label2This is the equivalent of call Label2, just with more bytes.
Label1: ld hl,ReturnLabel push hl jp Label2ReturnLabel:
Actually, a call Label2 equivalent would look like this:Code: [Select]Label1: ld hl,ReturnLabel push hl jp Label2ReturnLabel:It won't be returning to Label1, it will return to the point after the call.
RetMoar: POP HL POP HL ret
b_call _GetCSC CP skDel JP Z, Quit (...) ; Can this get executed, even though you press the Del button? ; If that's true, things just've gotten much more complicated :cQuit: POP HL POP HL ret