NBC statements

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

NBC statements

Post 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?

Code: Select all

#include "NXTDefs.h"
I see some programs that have it, and some that don't.

Edited for correction.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NBC statements

Post 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

Code: Select all

mov <SomeVariableNameHere>, 53
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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NBC statements

Post by mattallen37 »

Okay, that answers my questions. Thanks X2 :D
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests