Author Topic: Executing "ret" twice?  (Read 5255 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55896
  • Rating: +3152/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Executing "ret" twice?
« Reply #15 on: October 12, 2010, 03:48:13 am »
On an off-topic note, I fixed your forum signature because it was not showing up properly
« Last Edit: October 12, 2010, 03:49:42 am by DJ Omnimaga »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Executing "ret" twice?
« Reply #16 on: October 12, 2010, 03:56:07 am »
You know, you can save your stack pointer first and then return out of an arbitrary number of nested calls at once without memory leaks.

Code: [Select]
;Say this is on the base level before you start calling everything
  ld (save_sp),sp

;Now start calling away...
  call L1
L1:
  call L2
L2:
  call L3
L3:
  ...
LN:

;Now you decide you want to return to the base level again,
;but you don't know how many nested subs you actually used.
;So you just load the base address directly into sp again.

  ld sp,(save_sp)

;You are now back at the base level again.
;So in essence, you have returned out of all the subroutines
;and can do as you please at the base level.
« Last Edit: October 12, 2010, 03:56:46 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline mapar007

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 550
  • Rating: +28/-5
  • The Great Mata Mata
    • View Profile
Re: Executing "ret" twice?
« Reply #17 on: October 12, 2010, 04:44:36 am »
You know, you can save your stack pointer first and then return out of an arbitrary number of nested calls at once without memory leaks.
<code block not quoted>

Ooh, I failed to think of that.
« Last Edit: October 12, 2010, 04:44:53 am by mapar007 »

SirCmpwn

  • Guest
Re: Executing "ret" twice?
« Reply #18 on: October 12, 2010, 08:45:17 am »
(...) Should never get executed if the del button is held down...
Try it with direct input and see again.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Executing "ret" twice?
« Reply #19 on: October 14, 2010, 03:15:23 am »
On an off-topic note, I fixed your forum signature because it was not showing up properly
Haha! That was a mindf**k to me.;) One moment my sign wasn't showing correctly and I was like "Meh, will fix that later", then I log in, and it was showing correctly... >.< Thanks though.
You know, you can save your stack pointer first and then return out of an arbitrary number of nested calls at once without memory leaks.
I'll try that, though my problem is still that it HAS to return to the base level by a RET command (for noob reasons).
But I guess that with your code that can be done easely.
Thanks Quigibo, you've saved my day once again.

EDIT:
Ah, figured out why/how Quigibo's script works.
Works PERFECTLY now, so problem solved. n_n
« Last Edit: October 17, 2010, 06:58:53 am by Jerros »


79% of all statistics are made up randomly.

Offline DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55896
  • Rating: +3152/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Executing "ret" twice?
« Reply #20 on: October 18, 2010, 12:54:19 am »
I'm glad to hear it works fine :D