Skip to main content
CNC.wiki

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.

Hakan Gündoğdu
Hakan Gündoğdu

CNC CARE Co-founder

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

SpecificationTechnical Details
Command CodesG65, G66, G66.1, G67
Modal GroupG65 is Non-modal (Group 00); G66 and G66.1 are Modal (Group 12); G67 cancels modal calls
Supported BrandsFanuc, Siemens, Mitsubishi
Critical ParametersFanuc: 6008#7 (IJK) and 6007#4 (CVA); Mitsubishi: #1241 (Macro argument L/P valid) and #11053; Siemens: $MC_EXTERN_FUNCTION_MASK
Main ConstraintArgument 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 G65 for one-time simple macro calls and G66 for modal calls repeating at every axis motion.
  • Always program the G67 cancel command immediately after modal macro operations to prevent rogue movements during clearance coordinates.
  • Set Fanuc parameter 6008#7 to 0 to enable automatic detection of Argument Specification II for complex multi-point coordinates.
  • Program I, J, and K addresses in strict alphabetical sequence when using Mitsubishi Argument Designation I to ensure correct variable mapping.
  • Switch the Siemens interpreter to native mode using G290 before reading $C_ system variables to prevent parsing aborts.
  • Avoid using prohibited addresses such as G or N as 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 as A, 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;

CategoryItem / CodeDescriptionValue / Details
Parameter6008#7 (IJK)Global argument behavior0 = Auto-determine Spec I/II; 1 = Strict Spec I
Parameter6007#4 (CVA)Decimal format parsing0 = NC format; 1 = Macro format
Parameter6020#4 (GAA)Prohibited address overridesAllows G (mapped to #28-#32) and L (mapped to #12)
Parameter6009#2 (MAA)M-code macro callsDetermines if address G becomes an argument
AlarmAlarm 129 (PS0129)Invalid address G useTriggered if GAA/MAA parameters prohibit G
AlarmAlarm 1095 (PS1095)Stack limit exceededTriggered if more than 10 sets of I/J/K are specified
AlarmAlarm 114 (PS0114)Format error in macroUndefined H code or illegal mathematical format
VersionT-SeriesLathe configurationRestricts addresses strictly to A, B, F, H, I, K, M, P, Q, R, S, T
VersionM-SeriesMachining center configurationSupports 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

CategoryItem / CodeDescriptionValue / Details
ParameterPSubroutine identifier4 to 8 digits (determined by machine data)
ParameterLSubroutine repetition countInteger value between 1 and 9999
System Mask$MC_EXTERN_FUNCTION_MASKMachine data bit configurationBit 6 sets P digit format; Bit 3 enables DIN code evaluation
AlarmAlarm 12720Program number missingTriggered when macro call lacks address P
AlarmAlarm 12722Mixed cycle and macro callTriggered when combining macro calls and canned cycles
AlarmAlarm 14016Conflicting block functionsConflict with M98, returns, or end-of-program codes
VersionBit 6 = 0Strictly pads P to 4 digitsPassing a program number > 4 digits causes an alarm
VersionBit 6 = 1Natively supports 8 digitsAccepts 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;

CategoryItem / CodeDescriptionValue / Details
Parameter#1241 (set13/bit5)Macro argument L/P validityEnables passing L/P to variables #12 and #16
Parameter#11053User program storage location0 = NC Memory; 1 = Hard Disk
AlarmP275Stack limit exceededTriggered if more than 10 sets of I/J/K are programmed
AlarmP33Program syntax errorTriggered by invalid L/P in M98 or illegal strings
VersionM800V/M80V SeriesCall mode dependenciesG65/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

FeatureFanucSiemensMitsubishi
Variable MappingLocal variables #1 to #33System variables $C_A to $C_ZLocal variables #1 to #33
Argument StackingSpec II maps up to 10 sets of I/J/K to variables #4 to #33Stores up to 10 sets in $C_I[0]... and tracks count in $C_I_NUMDesignation II maps up to 10 sets of I/J/K to variables #4 to #33
Decimal PrecedenceLast specified argument type takes precedence in mixed blocks— (no source)Later specified address value is valid
Prohibited AddressesG/L/N/P are blocked; G/L can be mapped using GAA parameterP, L, O, N must be integers; real values trigger alarmsG/N blocked in G65/G66; L/P can be enabled via parameter #1241
Interpreter SwitchNative Custom Macro BRequires G290 to evaluate system variables in subprogramNative 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.0 is assigned to local variable #1.
  • Value 2.0 is assigned to local variable #2.
  • Value 15.0 is assigned to local variable #24.
  • Value 25.0 is 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.0 is mapped to $C_A.
  • Value 20.0 is mapped to $C_C.
  • Value 30.0 is mapped to $C_X.
  • Value 40.0 is mapped to $C_Z.
  • Array variable $C_I[0] is assigned 50.0, $C_J[0] is assigned 70.0, $C_K[0] is assigned 60.0.
  • The second instance of address I assigns 80.0 to $C_I[1], and $C_I_NUM is updated to 2 to 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.1 is mapped to local variable #1 (address A).
  • Value -2.2 is mapped to local variable #2 (address B).
  • Address D maps to #7, assigning 3.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 #7 is finalized with the value 7.7.

Error Analysis and Troubleshooting

BrandAlarm CodeTrigger ConditionOperator SymptomRoot Cause / Fix
FanucAlarm 129Commanding address G as an argument when not permittedCNC execution halts immediately; screen displays alarm messageGAA/MAA parameters are disabled; enable parameter 6020#4 or modify G-code
FanucAlarm 1095Programmed more than 10 sets of I/J/K in Argument Spec IIControl halts cycle; program stops before motion beginsSpec II stacking exceeded; reduce I/J/K pairs to 10 or fewer
SiemensAlarm 12720Calling G65/G66 macro without program number address PInterpreter aborts execution; cycle start lamp turns offMissing P address in NC block; specify program number P_ in macro call
SiemensAlarm 12722Mixing canned cycles and G65/G66 macro calls in same blockControl rejects block; display shows macro and cycle conflictCombined G81-G89 and G65/G66 in one block; separate them into two blocks
MitsubishiP275Commanding more than 10 sets of I/J/K in Designation IIAxis movement is inhibited; alarm status is activatedStacking limit exceeded; keep repeated I/J/K sets to 10 or fewer
MitsubishiP33Invalid L/P address in M98 subprogram callProgram halts with syntax errorParameter #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.

Ask AI Assistant
Hakan Gündoğdu
Hakan Gündoğdu
  • 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