Re: A83:'ret'


[Prev][Next][Index][Thread]

Re: A83:'ret'




Hmm. In my RPG I used this technique (which is over-complicated):

at the beginning, push a weird value (e.g. $ffff)

do stuff

at the moment on which you want to quit (and clear the stack),

pop until you reach $ffff

ret

that's all,
Frank Schoep
====================
Forever For Now
http://foreverfornow.cjb.net
dsfs98@concepts.nl
====================

-----Oorspronkelijk bericht-----
Van: D Weiss <dwedit@hotmail.com>
Aan: assembly-83@lists.ticalc.org <assembly-83@lists.ticalc.org>
Datum: dinsdag 30 januari 2001 2:38
Onderwerp: Re: A83:'ret'


>
>I use the stack save to allow the pressing of Clear to quit at any time
>regardless of the stack.  It sure beats checking for clear and
painstakingly
>calculating the number of pop hl's before the ret.
>
>
>>From: "David Phillips" <david@acz.org>
>>Reply-To: assembly-83@lists.ticalc.org
>>To: <assembly-83@lists.ticalc.org>
>>Subject: Re: A83:'ret'
>>Date: Mon, 29 Jan 2001 17:30:21 -0700
>>
>>
>>As several people suggested, you can save the stack pointer at the
>>beginning
>>of your program and restore it at the end as a sort of "safety net" in
case
>>you screw things up.  However, this is generally not good practice and
>>should be avoided if at all possible.  A well written program will never
>>need to manually restore the stack.  Usually having a corrupt stack is a
>>sign of a bug.  Think about it: why are you randomly pushing values that
>>you
>>aren't going to pop off?  Or why are you calling a routine that you are
not
>>going to return from?  When writing complex routines that use a lot of
>>registers that also involve some complex logic, it sometimes be tricky to
>>make sure you don't mess up the stack, but that doesn't mean you should
let
>>it become corrupted.  It's still a bug.
>>
>>About the only time you would need to clear the stack is for error
>>handling.
>>But on a calculator, you don't really need to be bailing out of routines
>>due
>>to random errors, simply because they don't exist.  In general programming
>>(such as games), there are only a couple things that I can think of that
>>would force you to abort the program.  The first would be not finding a
>>required variable, such as graphics or levels.  In this case, you would
>>probably do the detection at the start of the program, and it would be
>>trivial to exit without corrupting the stack.  The other instance would be
>>needing to allocate variables, either for more memory or to save a high
>>score.  Again, these are going to happen at some fixed point in the
>>program,
>>and not just at any random time.  For something like C++'s exception
>>handling, saving and restoring the stack could be genuinely useful.  But
as
>>I said before, you don't really need that on a calculator.  Using it for
>>any
>>other purpose is just going to make it harder on yourself, because you're
>>using very poor coding methods and introducing very difficult to find bugs
>>into your program.
>>
>> > If you use al lot of 'push' and 'pop' during a program, your calculator
>>can
>> > easily crash when trying to exit the program with the usual 'ret'(i'm
>> > writing for ION btw, but i don't think that has an influence)
>> > Is there a way of avoiding crashes or do you just have count how many
>>times
>> > you pushed a register and then pop it as many times? (and that's not so
>> > easy! So i hope there is another way...)
>>
>>
>>
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>