Archive: Invalid Opcode... bug?


Invalid Opcode... bug?
  I discovered a problem that I'm not sure is a bug or not. Maybe someone can help me understand this:

Look at this very simplified script:


name "My Test"

>outfile "blah.exe"
>ShowInstDetails show

Section
SectionEnd

>Function .onInit
exch$0
pop $R0
MessageBox MB_OK "here it is:***91;$R0***93;"
>FunctionEnd
>
If I compile this script, I get no errors. But, when I run the resulting EXE, I get an invalid Opcode error.

By making changing the .onInit function to push $0 (instead of exch $0), then it runs fine.

I've tried assigning values to $0, using $1 instead of $0, and even using my own variable, but each time, I get the Opcode error when I use the Exch call.

ideas?

Stack is empty on both exch and pop commands. Please read Manual 4.9.9.1, 4.9.9.2. Push copies your variable to stack so you can read it later using Pop.



onInit

exch$0
pop $R0
MessageBox MB_OK "here it is:***91;$R0***93;"
>FunctionEnd
>
a)

exch $0 

>
$0 is "empty", what are you exchanging from?
b)

Pop $R0 

>
$R0 is "empty", why are you poping an empty variable?

Not exactly. Exch $0 replaces the item on the stack with the value of $0 and places the value of $0 in its place on the stack. $0 being empty is not the problem. It is the fact that the stack is empty so no value can be put into $0 because no value exists!

-Stu


In answer to Joel's question about popping an empty variable:
I was just trying to illustrate the problem using the simplist means possible. (When I originally found the problem, it was in a more complex--and more useful--function.)
;)


After re-examing the docs, I did find this:

...If there are not enough items on the stack to accomplish the exchange, a fatal error will occur...
But, oddly, no such problem is mentioned with PUSH. So, I guess I have my answer. (Thanks, Joel.)

However, I still find it a bit odd that the outcomes are not consistant. If someone out there has a more technical explanation, I'd be curious to hear it. But, at least for now I can say that I know enough to code around it.

Thanks for help--you guys are GREAT! :up:

See my post above.

-Stu