Argument Assignment in CNC Macro Calls: G65 and G66 Guide
Master G65 and G66 macro argument assignment on Fanuc, Siemens, and Mitsubishi. Prevent hard tool collisions, format variables, and avoid alarm PS0129.
Introduction to Macro Argument Assignment
An uncommanded rapid motion plunging a spindle directly into a workpiece clamp or a rigid chuck is the immediate physical consequence of a corrupted macro argument assignment. In parametric programming, when a main program passes coordinates and dimensions via a G65 or G66 call, a single incorrect parameter setting or an out-of-sequence address mapping corrupts the mathematical logic within the subprogram. Before the operator can react, the CNC controller processes the misaligned data, calculates a distorted toolpath, and drives the cutter at rapid traverse into the workholding vise jaw or spindle housing. This causes catastrophic tool breakage, a scrapped part, and severe mechanical damage to the machine tool.
Technical Summary of Macro Call Commands
| Specification | Technical Details |
|---|---|
| Command Codes | G65, G66, G66.1, G67 |
| Modal Group | G65 is Non-modal (Group 00); G66 and G66.1 are Modal (Group 12); G67 cancels modal calls |
| Supported Brands | Fanuc, Siemens, Mitsubishi |
| Critical Parameters | Fanuc: 6008#7 (IJK) and 6007#4 (CVA); Mitsubishi: #1241 (Macro argument L/P valid) and #11053; Siemens: $MC_EXTERN_FUNCTION_MASK |
| Main Constraint | Argument stacking is limited to 10 sets of I, J, K coordinates; conflicting codes cannot be combined in the same program block |
Quick Read: Key Takeaways for Operators
- Choose
G65for one-time simple macro calls andG66for modal calls repeating at every axis motion. - Always program the
G67cancel command immediately after modal macro operations to prevent rogue movements during clearance coordinates. - Set Fanuc parameter
6008#7to 0 to enable automatic detection of Argument Specification II for complex multi-point coordinates. - Program
I,J, andKaddresses in strict alphabetical sequence when using Mitsubishi Argument Designation I to ensure correct variable mapping. - Switch the Siemens interpreter to native mode using
G290before reading$C_system variables to prevent parsing aborts. - Avoid using prohibited addresses such as
GorNas arguments unless explicitly enabled via specific machine parameters.
Basic Concepts of CNC Macro Variables
Argument assignment during macro calls provides the capability to transfer numerical values directly from the calling block into local variables inside the subroutine. This allows programmers to write universal, parameter-driven programs that can be reused for different parts and operations by simply changing the inputs in the call line. By using this method, coordinates, feedrates, spindle speeds, or geometric inputs are dynamically injected into the macro subprogram.
To understand how this operates, we must refer to the relationship between the G-code block addresses and the internal variable registers. For instance, in a Fanuc or Mitsubishi system, an address letter like A corresponds to variable #1, while B corresponds to #2. In a Siemens system, the address letters transfer directly to named system variables like $C_A and $C_B. Ensuring proper parameter settings, alphabetical order of arguments where applicable, and avoiding duplicate variable mappings are universal requirements for preventing logic errors that can lead to physical collisions or scrap parts.
Command Structure and Syntax Rules
To initiate a macro subprogram call and transfer data, the CNC interpreter must process specific command codes that define both the call behavior and the destination program. The primary commands are G65 for a simple, non-modal call, and G66 for a modal call. While a simple call executes the macro subprogram exactly once in the block where it is called, a modal call remains active and executes the subprogram on every subsequent block containing motion commands until it is canceled.
During these calls, address characters specified in the main program block are mapped to local variables in the subprogram. A standard call block must include the program number address P and optionally a repetition count L. All other letters act as arguments passing values.
Syntax for macro calls on different systems:
- Fanuc/Mitsubishi:
G65 P_ L_ <arguments>; - Siemens:
G65 P_ L_ <Arguments>;
Parameters used in macro call structures:
P: Subroutine program number (or identifier).L: Number of times the subroutine repeats (repetitions).<arguments>: Address characters passing values to local variables (such asA,B,C,I,J,K).
Brand Applications: Controller Specific Implementations
Fanuc
In Fanuc Custom Macro B, parameter 6008#7 and parameter 6007#4 govern how coordinates are mapped. These parameters determine if the controller uses Argument Specification I or II.
The following syntax illustrates a simple G65 macro call and a stacked Argument Specification II call:
; Fanuc simple call: G65 P1000 A1.0 B2.0 X15.0 Y25.0;
; Fanuc stacked call (Argument Spec II): G66 P9100 I10.0 J20.0 K30.0 I40.0 J50.0 K60.0;
| Category | Item / Code | Description | Value / Details |
|---|---|---|---|
| Parameter | 6008#7 (IJK) | Global argument behavior | 0 = Auto-determine Spec I/II; 1 = Strict Spec I |
| Parameter | 6007#4 (CVA) | Decimal format parsing | 0 = NC format; 1 = Macro format |
| Parameter | 6020#4 (GAA) | Prohibited address overrides | Allows G (mapped to #28-#32) and L (mapped to #12) |
| Parameter | 6009#2 (MAA) | M-code macro calls | Determines if address G becomes an argument |
| Alarm | Alarm 129 (PS0129) | Invalid address G use | Triggered if GAA/MAA parameters prohibit G |
| Alarm | Alarm 1095 (PS1095) | Stack limit exceeded | Triggered if more than 10 sets of I/J/K are specified |
| Alarm | Alarm 114 (PS0114) | Format error in macro | Undefined H code or illegal mathematical format |
| Version | T-Series | Lathe configuration | Restricts addresses strictly to A, B, F, H, I, K, M, P, Q, R, S, T |
| Version | M-Series | Machining center configuration | Supports fully expanded list: A, B, D, F, H, I, J, K, L, M, P, Q, R, S, T, X, Y, Z |
Programmers must verify parameter settings before executing programs that contain stacked I, J, and K coordinates, as an incorrect setting will lead to coordinate overwrites and mechanical collisions.
Siemens
Siemens Sinumerik controllers do not map arguments to numbered local variables. Instead, they write values directly into predefined system variables like $C_A to $C_Z when executing a call.
The following example illustrates how parameters are declared in a G65 call block and captured inside the subprogram:
; Siemens call block: N30 G65 P10 F55 X150. Y100. S2000
; Siemens subprogram parameter retrieval: N15 X_AXIS = $C_X Y_AXIS = $C_Y SPEED = $C_S FEEDRATE = $C_F
| Category | Item / Code | Description | Value / Details |
|---|---|---|---|
| Parameter | P | Subroutine identifier | 4 to 8 digits (determined by machine data) |
| Parameter | L | Subroutine repetition count | Integer value between 1 and 9999 |
| System Mask | $MC_EXTERN_FUNCTION_MASK | Machine data bit configuration | Bit 6 sets P digit format; Bit 3 enables DIN code evaluation |
| Alarm | Alarm 12720 | Program number missing | Triggered when macro call lacks address P |
| Alarm | Alarm 12722 | Mixed cycle and macro call | Triggered when combining macro calls and canned cycles |
| Alarm | Alarm 14016 | Conflicting block functions | Conflict with M98, returns, or end-of-program codes |
| Version | Bit 6 = 0 | Strictly pads P to 4 digits | Passing a program number > 4 digits causes an alarm |
| Version | Bit 6 = 1 | Natively supports 8 digits | Accepts program numbers up to 8 digits without padding |
Operators must place all argument parameters strictly after the program call-up codes to avoid immediate parsing alarms and aborted cycles.
Mitsubishi
Mitsubishi controllers assign arguments to local variables #1 to #33. Programmers can use parameter #1241 to enable L and P variables.
The following block represents a Mitsubishi macro call passing arguments and showing overwrite precedence in mixed format calls:
; Mitsubishi simple call: G65 P9900 A60. S100. F800;
; Overwrite demonstration: G65 A1.1 B-2.2 D3.3 I4.4 I7.7;
| Category | Item / Code | Description | Value / Details |
|---|---|---|---|
| Parameter | #1241 (set13/bit5) | Macro argument L/P validity | Enables passing L/P to variables #12 and #16 |
| Parameter | #11053 | User program storage location | 0 = NC Memory; 1 = Hard Disk |
| Alarm | P275 | Stack limit exceeded | Triggered if more than 10 sets of I/J/K are programmed |
| Alarm | P33 | Program syntax error | Triggered by invalid L/P in M98 or illegal strings |
| Version | M800V/M80V Series | Call mode dependencies | G65/G66 prohibit G and N; G66.1 allows G and N arguments |
Operators must command I, J, and K variables in alphabetical order during Designation I to prevent incorrect parameter mappings.
Brand Comparison: Fanuc, Siemens, and Mitsubishi
| Feature | Fanuc | Siemens | Mitsubishi |
|---|---|---|---|
| Variable Mapping | Local variables #1 to #33 | System variables $C_A to $C_Z | Local variables #1 to #33 |
| Argument Stacking | Spec II maps up to 10 sets of I/J/K to variables #4 to #33 | Stores up to 10 sets in $C_I[0]... and tracks count in $C_I_NUM | Designation II maps up to 10 sets of I/J/K to variables #4 to #33 |
| Decimal Precedence | Last specified argument type takes precedence in mixed blocks | — (no source) | Later specified address value is valid |
| Prohibited Addresses | G/L/N/P are blocked; G/L can be mapped using GAA parameter | P, L, O, N must be integers; real values trigger alarms | G/N blocked in G65/G66; L/P can be enabled via parameter #1241 |
| Interpreter Switch | Native Custom Macro B | Requires G290 to evaluate system variables in subprogram | Native Custom Macro |
Technical Analysis of Controller Behavior
Analyzing the differences in argument assignment across these controllers reveals three distinct architectural paths. Fanuc relies heavily on parameter-driven address aliasing and unique multiplexing capabilities. By supporting Argument Specification II, Fanuc allows programmers to bypass alphabetical address limits by repeating I, J, and K up to ten times in a single block. The controller automatically and invisibly sequences these repeated addresses into local variables #4 through #33. Parameters like 6020#4 (GAA) and 6009#2 (MAA) also allow programmers to override the default prohibition of G and L addresses, mapping them directly to variables #28-#32 and #12.
Siemens rejects the numbered local variable system in favor of self-documenting system variables. Instead of pushing values into numbered local variables, Siemens assigns arguments to variables named after the axes or functions themselves, such as $C_X or $C_S. For array arguments, Siemens implements native array handling, stacking repeated I, J, and K inputs into indexed arrays (like $C_I[0]) and tracking the count via $C_I_NUM. Siemens also supports dynamic cross-compilation, allowing programmers to toggle between high-level mode (G290) and ISO dialect mode (G291) to perform complex mathematics on the parameters.
Mitsubishi provides a robust middle ground with specialized overwrite logic and call-mode-dependent address capturing. In cases where overlapping formats are programmed in the same block, Mitsubishi's interpreter prioritizes and accepts the latter value without halting the machine. The controller also offers unique flexibility through parameter #1241, which allows the L and P addresses to be passed as variables #12 and #16. In Modal Call B (G66.1), Mitsubishi allows even reserved addresses like G and N to be captured as arguments #10 and #14, provided they appear after the executable NC codes.
Program Examples and Code Blocks
Fanuc Example
G65 P1000 A1.0 B2.0 X15.0 Y25.0;
dry run
- The interpreter reads G65 and shifts control to program O1000.
- Value
1.0is assigned to local variable#1. - Value
2.0is assigned to local variable#2. - Value
15.0is assigned to local variable#24. - Value
25.0is assigned to local variable#25. - The macro program processes the operations using these variables and returns to the main program via M99.
Siemens Example
G65 P1234 A10. C20. X30. Z40. I50. K60. J70. I80.
dry run
- The interpreter reads G65 and calls program number 1234.
- Value
10.0is mapped to$C_A. - Value
20.0is mapped to$C_C. - Value
30.0is mapped to$C_X. - Value
40.0is mapped to$C_Z. - Array variable
$C_I[0]is assigned50.0,$C_J[0]is assigned70.0,$C_K[0]is assigned60.0. - The second instance of address I assigns
80.0to$C_I[1], and$C_I_NUMis updated to2to track the array size.
Mitsubishi Example
G65 A1.1 B-2.2 D3.3 I4.4 I7.7;
dry run
- The interpreter processes the simple call.
- Value
1.1is mapped to local variable#1(address A). - Value
-2.2is mapped to local variable#2(address B). - Address D maps to
#7, assigning3.3. - The first instance of address I maps to
#4(value 4.4). - The second instance of address I maps to
#7(value 7.7) due to Designation II sequencing. Because both D and the second I map to#7, the overwrite logic prioritizes the latter argument, and variable#7is finalized with the value7.7.
Error Analysis and Troubleshooting
| Brand | Alarm Code | Trigger Condition | Operator Symptom | Root Cause / Fix |
|---|---|---|---|---|
| Fanuc | Alarm 129 | Commanding address G as an argument when not permitted | CNC execution halts immediately; screen displays alarm message | GAA/MAA parameters are disabled; enable parameter 6020#4 or modify G-code |
| Fanuc | Alarm 1095 | Programmed more than 10 sets of I/J/K in Argument Spec II | Control halts cycle; program stops before motion begins | Spec II stacking exceeded; reduce I/J/K pairs to 10 or fewer |
| Siemens | Alarm 12720 | Calling G65/G66 macro without program number address P | Interpreter aborts execution; cycle start lamp turns off | Missing P address in NC block; specify program number P_ in macro call |
| Siemens | Alarm 12722 | Mixing canned cycles and G65/G66 macro calls in same block | Control rejects block; display shows macro and cycle conflict | Combined G81-G89 and G65/G66 in one block; separate them into two blocks |
| Mitsubishi | P275 | Commanding more than 10 sets of I/J/K in Designation II | Axis movement is inhibited; alarm status is activated | Stacking limit exceeded; keep repeated I/J/K sets to 10 or fewer |
| Mitsubishi | P33 | Invalid L/P address in M98 subprogram call | Program halts with syntax error | Parameter #1241 is active, making L/P variable arguments; use standard M98 without L/P |
Application Note: Advanced Parameter Configuration
Tool degradation, ruined workpieces, and hard structural collisions are the immediate results when macro variables receive corrupted coordinate inputs. Operators must ensure that parameter 6008#7 (IJK) is configured to 0 before executing programs that stack multiple I, J, and K arguments. If this parameter is set to 1, the interpreter ignores Argument Specification II and processes all coordinates via Specification I, causing subsequent coordinate inputs to overwrite previous variable locations. When this corrupted variable represents a critical coordinate (such as a Z-axis depth or an X-axis radial offset), the machine will plunge the tool directly into the chuck, clamp, or vise jaw instead of bypassing it. Similarly, parameter 6007#4 (CVA) must be checked: if a program is written expecting standard NC format inputs (where X10 represents 10.0 mm) but the controller is set to macro format, the value will be parsed as 0.01 mm. This scaling error ruins the toolpath, causing either an unexpected tool crash or a scrapped part.
Related Command Network
- G65 Custom Macro B: Simple non-modal macro call command used to initiate subprograms and transfer variable values.
G66: Modal macro call command that repeats the subroutine execution at every block containing axial movement until canceled.G67: Modal cancel command used to deactivate G66 or G66.1 modal cycles and return to normal interpreter execution.- Writing and Calling Subprograms: General subprogram execution command that calls secondary programs but does not allow variable argument transfer.
- Macro Logical Operators: Logical operations used inside macro subprograms to validate transferred arguments and control program flow.
Conclusion and Best Practices
Maintaining correct argument specifications and matching parameter setups is mandatory for safe CNC macro execution. Checking parameters like 6008#7 on Fanuc, $MC_EXTERN_FUNCTION_MASK on Siemens, and #1241 on Mitsubishi before running parametric subprograms eliminates the risk of corrupted coordinate variables. Standardizing program formatting and validating the execution mode of the controller ensures reliable cycles and protects valuable tooling from unexpected rapid motion crashes.
Frequently Asked Questions
What happens if I program I, J, and K out of alphabetical sequence in a macro call?
Programming these addresses out of order on Mitsubishi Designation I causes incorrect mapping. The interpreter will assign values to the wrong local variables. To prevent this, always write macro call blocks with arguments organized alphabetically, or enable Designation II if you need to stack coordinate groups.
Why does my program throw an alarm when passing a program number with more than four digits?
On Siemens systems, bit 6 of the machine data parameter $MC_EXTERN_FUNCTION_MASK controls the program number length. If this bit is set to 0, numbers with more than 4 digits are rejected. The operator should verify this machine data setting or change the subroutine program number to fit within the 4-digit limit.
How can I pass the G and L addresses as variables in Fanuc Custom Macro B?
By default, addresses G and L are prohibited as arguments. To use them, you must enable parameter 6020#4 (GAA), which maps the first five G addresses to variables #28-#32 and address L to #12. Ensure this parameter is enabled on the machine tool before running programs containing these aliased arguments.
Still not resolved?
Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

- CNC CARE Co-Founder (May 2025 - Present)
- Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
- Reis CNC Service Engineer (2003 - 2005)
- Ören Kalıp CNC Mold Line Team Leader (1999 - 2002)
With over 25 years of experience working in all areas of the CNC machine industry, I continue my activities as a co-founder of CNC CARE, where we offer brand-independent consulting, engineering, and original spare parts services.
Related Articles
Other articles on this topic
Enabling Fanuc 3D Interference Check: Parameters and Setup
Configure Fanuc 3D Interference Check parameters. Learn how to set parameter 10930#0, troubleshoot Alarm PS0492, and prevent crashes with iHMI solid models.
Configuring Fanuc Custom Macro Enable Parameters (0932 & 8135)
Learn how to configure Fanuc custom macro enable parameters 0932 and 8135, expand common variables, and resolve Alarm 123 on CNC controller boards.
Fanuc Tool Life Management Parameters Configuration Guide
Learn to configure Fanuc tool life management parameters like 6800 and 6810. Prevent crash alarms 156 and 159 to enable unmanned, collision-free CNC machining.
Fanuc Rigid Tapping Optimal Acceleration Parameters Config Guide
Learn how to enable Fanuc optimum torque acceleration for rigid tapping using parameter 11420#0, tune gears 1 to 4, and resolve servo tracking alarm SP0741.