Printed from Kezuriba (kezuriba.net/en/nc/m98/)
M98
Machining center, LatheSubprogram call
Format and notes
M98 P_ (ISO dialect: the lower 4 digits of P are the program number and the upper digits are the repeat count. Example: M98 P30021 calls O0021 three times)
- The subprogram ends with M99
- Arguments cannot be passed. To pass values, use G65
- The number of digits when the repeat count is combined into P differs between sources. The 2007 edition of the Siemens ISO dialect manual says 4 digits for the repeat count in the lathe manual and 3 digits in the milling manual. The repeat count can also be written with L, and L takes priority if both are given. If the program number is 8 digits, the repeat count cannot be combined into P and L is required (Siemens ISO dialect)
- How each FANUC edition handles this (whether the repeat count can be combined into P, whether L can be used, and how many digits) could not be confirmed in public documents. Check the operator's manual for your machine
- There is a limit to nesting depth (multiple calls): 4 levels in the Siemens ISO dialect, 8 levels on Mitsubishi Electric
- M98/M99 are handled inside the NC (Siemens ISO: M90–M99 are processed internally by the NC)
- Even the same “P” means the repeat count in Siemens native language, the opposite of the ISO dialect (program number)
M00–M02, M30, M98 and M99 stop, end or call programs, and their meaning is almost the same in all the sources we checked (sources that differ are listed in the table below). M98 and M99 are handled inside the CNC (the Siemens ISO dialect manual treats M90–M99 as CNC-internal). Most other M codes are assigned by the machine builder.
Full guide with examples: Intro to custom macros and subprograms (M98, M99, G65, # variables)
Try it in the simulator (machining center)
M98 P2000 L3 calls subprogram O2000 three times and M99 returns. Inside it is incremental (G91), so each call moves 15 mm in X.
Simulator with exercises: Machining center page
Differences between controls and machines
The same code can be written or assigned differently depending on the CNC control and the machine builder. Always check your machine’s manual.
“One source / reference” rows were confirmed in only one source. “CAM post output / reference” rows show what a CAM post processor outputs and could not be confirmed in the control maker’s own public documents.
| Source | Machine | Item | Detail |
|---|---|---|---|
| Haas | Machining center | Format | M98 P_ (number) L_ (repeat count 1–99)Haas specifies the repeat count with L. A subprogram within the same program is M97 |
| Siemens (ISO dialect) | Lathe | Format | When combining the repeat count into P, use a 4-digit count + 4-digit number (lathe manual). The count can also be written with L_ (1–9999), and L takes priority |
| Siemens (ISO dialect) | Machining center | Format | When combining the repeat count into P, use a 3-digit count + 4-digit number (milling manual) |
| Mitsubishi Electric | — | Format | M98 P_ H_ L_ ,D_. P is the number (up to 8 digits), H is the sequence number in the called program (start from that line), L is the repeat count 1–9999 (L0 is not executed), and ,D is the device number. It can also be called with M98 <file name>. Nesting is 8 levels |
| Siemens (native) | — | Format | Call a subprogram just by writing its name. P is the repeat count (1–9999), the opposite of P (number) in the ISO dialect |
| LinuxCNC | — | Format | M98 P_ L_ can be used. L0 is not executed. Place the subprogram to be called after the call |
| CAM post for Okuma (Autodesk) | Machining center | Format | Call with CALL O_ (4-character name); the subprogram ends with RTS. How to write the repeat count is not confirmed in public documentsCAM post output / reference |
Frequently asked questions about M98
- What is M98 (Subprogram call) used for and how is it formatted in a CNC program?
- M98 commands "Subprogram call" on Machining center, Lathe. The standard program format is "M98 P_ (ISO dialect: the lower 4 digits of P are the program number and the upper digits are the repeat count. Example: M98 P30021 calls O0021 three times)". The subprogram ends with M99
- Is M98 a modal code or a one-shot (non-modal) code?
- Whether M98 acts modally or as a single-block command depends on the CNC control and the machine builder’s PLC ladder implementation. Check your machine’s active modal status screen and programming manual before running in auto mode.
- Does M98 work differently on machining centers (mills) versus CNC lathes?
- M98 is primarily used on Machining center, Lathe. Depending on the machine type and the lathe G-code system (System A, B, or C), this code may be unavailable or assigned to a different function, so verify against your machine tool manual.
- Are there differences in M98 across FANUC, Mitsubishi, Okuma, Haas, and Siemens controls?
- Yes. Control builders such as FANUC, Mitsubishi Electric (M80/M800), Okuma (OSP), Haas, Mazak, Siemens (SINUMERIK ISO dialect), and Heidenhain can differ in argument letters, decimal-point rules, and optional parameters for M98. Review the control comparison table above and verify the exact syntax in your machine’s programming manual before proving out the program.
- When should I use M98 (Subprogram Call) versus G65 (Custom Macro Call)?
- M98 Pxxxx simply branches to a subprogram (with optional L repeat count) without passing parameters. G65 Pxxxx lets you pass letter arguments (A, B, C, etc.) into local variables (#1–#33), making G65 ideal when the same routine needs different diameters, depths, or coordinates.
Sources
The meaning of this code agrees in two or more sources from different publishers. Explanations are written in our own words.
- Siemens AG — SINUMERIK 802D sl/840D/840D sl/840Di/840Di sl/810D Programming Manual ISO Milling, 04.2007 Edition (6FC5398-7BP10-0BA0) cache.industry.siemens.com
- Haas Automation, Inc. — Mill Operator's Manual – 18 Mill M-Codes (online version) haascnc.com
- Haas Automation, Inc. — Lathe Operator's Manual – 17 Lathe M-Codes (online version) haascnc.com
- Haas Automation, Inc. — M98 Sub Program Call (machining center, per-code explanation page) haascnc.com
- Siemens AG — SINUMERIK 802D sl/840D/840D sl/840Di/840Di sl/810D Programming Manual ISO Turning, 04.2007 Edition cache.industry.siemens.com
- Mitsubishi Electric — MITSUBISHI CNC 700/70 Series Programming Manual (Lathe System) (IB-1500057) mitsubishielectric.com
- Siemens AG — SINUMERIK 840D sl/840D/840Di sl/810D Fundamentals, Programming Manual, Edition 08/2005 (6FC5398-1BP10-0BA0) cache.industry.siemens.com
- LinuxCNC project — O Codes (LinuxCNC Documentation) linuxcnc.org
- Autodesk — OKUMA milling post processor (okuma.cps, Fusion post library) cam.autodesk.com