If you have used Fanuc-style subprograms with M98 and M99, LinuxCNC does the same job a different way: with O-words. They cover subroutines, loops, and conditionals, and the model feels more like a small programming language than a pair of M-codes.

The building blocks

  • Subroutine: define a reusable block between o100 sub and o100 endsub, then run it with o100 call. The number labels the block.
  • Parameters: values passed on the call line become #1, #2, and so on inside the subroutine.
  • Loop: o101 while [condition]o101 endwhile repeats a block.
  • Conditional: o102 if [condition]o102 endif runs a block only when the condition holds.

A simple example

o100 sub          (define subroutine 100)
  G0 Z5
  G1 Z-1 F100
o100 endsub

o100 call         (run subroutine 100)
M2                (end program)

The subroutine is defined once and run with a single call. Loops and conditionals let you repeat or branch without rewriting code.

LinuxCNC O-words vs Fanuc M98/M99

TaskLinuxCNCFanuc-style
Define a subroutineoNNN sub / oNNN endsubA separate program number
Call itoNNN callM98 P...
Returnimplicit at endsubM99
LoopoNNN while / endwhilemacro / repeat count
ConditionaloNNN if / endifmacro B (optional)

Where this fits

O-words are an advanced topic, well past the common G-codes. Make the basics automatic first with beginner CNC code practice, and if you also work on Fanuc-style controls, compare with M98 and M99 subprograms. If you are building a LinuxCNC machine, note that the Mesa card is hardware that does not change these codes, and there is a wider set of open-source G-code practice software to run and visualize them. A free tool like G-Code Sprint drills the foundational codes; confirm O-word details against the LinuxCNC documentation, since this is an educational overview.

Bottom line

LinuxCNC uses O-words, o-sub/endsub with o-call, plus while and if, for subroutines, loops, and conditionals. It is the LinuxCNC equivalent of Fanuc M98/M99, with more flexibility and different syntax.

Sources

Frequently asked questions

What are O-words in LinuxCNC?

O-words are LinuxCNC’s program-flow commands: subroutines, loops, and conditionals. A subroutine is defined with o100 sub and o100 endsub and called with o100 call. They are LinuxCNC’s equivalent of, and more flexible than, Fanuc-style M98/M99 subprograms.

How do you call a subroutine in LinuxCNC?

Define it between oNNN sub and oNNN endsub, then run it with oNNN call, optionally passing parameters that become #1, #2, and so on inside the subroutine. The number NNN labels that block.

Is LinuxCNC O-word the same as Fanuc M98?

They do the same job, reusing a block of code, but the syntax is different. Fanuc uses M98 to call and M99 to return; LinuxCNC uses o-sub/endsub and o-call, plus while and if for loops and conditionals. Confirm the exact behavior in the LinuxCNC docs.

G-Code Sprint is a study and practice tool only. It is not a CNC simulator, machine controller, or safety authority. Always follow your instructor, employer, machine manual, and shop safety procedures.