[comp.sys.handhelds] HP-28S Lockup was Re:

louxj@nyssa.CS.ORST.EDU (John W. Loux) (03/14/90)

In article <9003081508.AA03715@GANDALF.LL.MIT.EDU> yasu@GANDALF.LL.MIT.EDU (Alan Yasutovich) writes:
>
>>Date: 7 Mar 90 20:39:07 GMT
>>
>>	Guess what!  Never run a program that uses variables that you
>>	forgot to define!
>>			/.......BYE BYE!!!!!!!!!!!
>
>
>		Just for laughs, the program was
>	ATOP DUP
>	TEMP +
>	'ATOP' STO
>	'ATOP1' STO
>	WHILE ATOP ATOP1 >
>	REPEAT
>	
>	"ATOP" and "AREC" were not defined.  Who knows what happened?
>	The HP28s flew south into "non-interruptable mode".
>***************************************************************************
>
>				  Alan

The problem is, as you say, that ATOP is undefined before runnning the
program.  The result is that 'ATOP+TEMP' (or whatever TEMP evaluates to) is
stored in 'ATOP'.  'ATOP' is also stored in 'ATOP1'.  Now, when ATOP is
evaluated in the WHILE clause, ATOP refers to itself and the evaluation
recurses.  If you MUST use global names in this way, perform some sort of test
to see whether they are defined or not.  Something like

		IF ATOP TYPE 6 ==
		THEN Undefined
		ELSE ProcessNormally
		END

Would do it.  The reason for all this is that when a name ``contains'' or
refers to nothing, the name itself is left on the stack as the result of its
evaluation.

I hope this helps.

John W. Loux
Solve ands Integrate Corp.
solvint!john@CS.ORST.EDU