Page 1 of 1
NBC statements
Posted: 08 Mar 2011, 07:09
by mattallen37
Is there any reason to use "set" instead of "mov"? I know that "mov" has advantages over "set", but is "set" better in any ways?
Is there any reason to include this line in a program that uses NBC?
I see some programs that have it, and some that don't.
Edited for correction.
Re: NBC statements
Posted: 08 Mar 2011, 21:31
by afanofosc
No need to #include NXTDefs.h since the compiler does it for you automatically.
The set opcode lets you set a variable to a word-sized (or smaller) constant value. It is beneficial only to the extent that it does not require that you have a variable in your dataspace that stores that particular constant value so that you can mov it into the place where it is needed. With mov even if you use a constant as the source value it actually requires a variable in the VM so the compiler dutifully creates a variable in the dataspace with a static initialization value equal to whatever constant value you used in your code. If you are initializing an int to 53 then you could use set and save a variable. The compiler automatically unifies these auto-constant variables that it creates so if you use
several times it will only create one variable that is statically initialized to 53.
I would probably suggest using mov more often than not.
John Hansen
Re: NBC statements
Posted: 08 Mar 2011, 22:52
by mattallen37
Okay, that answers my questions. Thanks X2