37796-8000
MACROS
June 1999
The expression on the left of the equal sign must always refer to a macro variable, whether directly or indirectly.
The following macro initializes a sequence of variables to any value. Here both direct and indirect assignments
are used.
O0300 (Initialize an array of variables) ;
N1 IF [#2 NE #0] GOTO2 (B=base variable) ;
#3000=1 (BASE VARIABLE NOT GIVEN) ;
N2 IF [#19 NE #0] GOTO3 (S=size of array);
#3000=2 (SIZE OF ARRAY NOT GIVEN) ;
N3 WHILE [#19 GT 0] DO1 ;
#19=#19-1 (DECREMENT COUNT) ;
#[#2+#19]=#22 (V=value to set array to) ;
END1 ;
M99 ;
The above macro could be used to initialize three sets of variables as follows:
G65 P300 B101. S20 (INIT 101..120 TO #0) ;
G65 P300 B501. S5 V1 (INIT 501..505 TO 1.0) ;
G65 P300 B550. S5 V0 (INIT 550..554 TO 0.0) ;
The decimal point in B101., etc. would be required.
Control Statements
Control statements allow the programmer to branch, both conditionally and unconditionally. They also provide
the ability to iterate a section of code based on a condition.
Unconditional Branch (GOTOnnn and M99 Pnnnn)
In the HAAS control, there are two methods of branching unconditionally. An unconditional branch will always
branch to a specified block. M99 P15 will branch unconditionally to block number 15. The M99 can be used
whether or not macros is installed and is the traditional method for branching unconditionally in the HAAS
control. GOTO15 does the same as M99 P15. In the HAAS control, a GOTO command can be used on the
same line as other G coding. The GOTO is executed after any other control commands as are traditional M
codes.
Computed Branch (GOTO#n and GOTO[expression])
Computed branching allows the program to transfer control to another block in the same subprogram. The
block can be computed on the fly, as in the case of the GOTO[expression] form, or the block can be passed in
through a local variable, as in the GOTO#n form.
The GOTO will round the variable or expression result that is associated with the Computed branch. For
instance, if #1 contains 4.49 and GOTO#1 is executed, the control will attempt to transfer to a block containing
N4. If #1 contains 4.5, then execution will transfer to a block containing N5.