Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: Ashbad on July 01, 2011, 08:32:01 pm
-
I have a question. I'm the horrible flavor of coder who doesn't fare well with manipulating the stack perfectly, so in case I run into difficulties with some code, I tried writing two small routines that would get the location of the stack (with an extra pop beforehand) and the value at the top of the stack before I even touch it myself, so when I do a final exit from the app, the stack looks as though it was never touched to the OS. Here is my code for this:
;start stack check initializer
;keeps track of app start location
;followed up later in case of emergency exits
StartStackCheckInit
pop hl
ld (OP6),hl ;load emergency resources into OP6
ld hl,0
adc hl,sp
ld (OP6+2),hl
ld hl,(OP6)
push hl
ret
StartStackCheckInit_end
;emergency exit call
;used only when an exit is REALLY REALLY REALLY needed
ExitUsingEmergencyResources
ld sp,(OP6+2)
ld hl,(OP6)
push hl
END_APP_RUN ;just a small stand-in for that bcall(_JForceNoCMD...) thing I always forget the name frequently
ExitUsingEmergencyResources_end
Looks like it'll work (from what I saw in Wabbit, it seemed to work fine there too -- however, I can't test on hardware ATM) but is it safe to sexually abuse the stack this much? Or is it even safe in general to attempt such a thing?
-
Is there a reason why you can't save SP somewhere at the very beginning of the app, then just restore that if you need to exit?
-
Bcall(_JForceNoCmd) already does this for you. It fixes the hardware stack, the floating point stack, and whatever else, so even if you're stack is leaking horribly you should still be able to call it and exit safely to the OS
-
Bcall(_JForceNoCmd) already does this for you. It fixes the hardware stack, the floating point stack, and whatever else, so even if you're stack is leaking horribly you should still be able to call it and exit safely to the OS
Oh, really? Thanks, that's a lot easier :)
-
Yeah thats why its ok to bcall it, even though it was technically meant to be a bjump.
-
Sorry if this is off-topic, but I lol'd at the topic title, which immediately made me figure out who started it, and it turned out I guessed right :P :
DJ_O also I just saw this in the new posts list: "Emergency Exiting out of an application by sexually abusing the stack" in the ASM sub forum
[23:21:34] DJ_O let me guess: The topic was started by Ashbad <.<
[23:21:42] shmibs yup
[23:21:48] DJ_O YES i was right
We didn't cheat by checking before :P
-
You know me too well *.*
-
wow DJ...
-
Don't worry I still like him ;D