Futurebasic/Language/Reference/register on

SyntaxEdit

REGISTER ON

REGISTER OFF

RevisedEdit

June 2001 (Release 5)

DescriptionEdit

The constant _registerVars is set up by the editor before compilation begins. The constant is zero if register variables are currently turned off and -1 if they are on. You may not change the status of the constant by overriding. It is for information purposes only. These are non-executable statements which affect the way the compiler treats variables which are defined farther down in the program. The REGISTER ON statement instructs the compiler to attempt to use CPU registers to store the values of subsequently-encountered variables. The REGISTER OFF statement instructs the compiler to use addressable memory (RAM) to store the values of all subsequently-encountered variables. These statements are global in scope; they affect all variables that are defined below the statement, whether they're defined in a local function or in the "main" part of your program. Your program can include several REGISTER ON and REGISTER OFF statements, if you wish to exercise finer control over how specific variables are used. If you don't specify either statement, the default condition is determined by how you've set this option in the "Compiler Preferences" dialog. The advantage of using register-based variables is speed. Many operations are faster by orders of magnitude when they use register-based variables. Only 1-byte, 2-byte and 4-byte variables can be stored in CPU registers. There are only a limited number of registers available, so it's possible that not all of your variables will be register-based even if you specify REGISTER ON. When using REGISTER ON, you should define your most frequently used variables first (just below the REGISTER ON); this will increase their chances of being assigned to a CPU register. The advantage of using RAM-based variables is versatility. There are certain operations that can't be performed using register-based variables; in particular, any operation that makes reference to a variable's address must use a RAM-based variable. This includes using expressions like VARPTR(myVar) and @myVar, and passing the variable to certain statements and functions which need to return a value into the variable. The compiler will generate an error if you attempt to use a register-based variable in such situations. Floating Point Registers While the specific set of registers used for most operations is designed to handle whole numbers, there is an additional set of registers on the PPC processor set aside for floating point values. It is important to note that all floating point registers are double precision. There is no advantage to attempting to use a single precision variable. In fact, the conversion to double precision may make it slower. This same feature is true of all math operations. Single precision variables are converted to double precision, the operation is performed, then the variable is converted back to its single precision state. In order to force a float into a register, you must dimension it between the LOCAL and the LOCAL FN statements. The following example shows register and non-register floats in a local function.

LOCAL DIM myRegisterVar# 'in register DIM myVar AS DOUBLE 'in register

LOCAL FN anything DIM myRamFloat# 'not in register DIM notInRegister AS DOUBLE 'not in register REM do anything END FN

Note: You can also use the DIM statement to selectively force certain variables to be RAM-based, even when REGISTER ON is in effect. Here are some items that force variables to be located in RAM:

DIM @var DIM var&;0,hi%,lo% DIM var.8

See AlsoEdit

DIM