CNC Machining Execution Program

Mar 04, 2026

Leave a message

Sometimes when programming machining, you might encounter a situation where a group of program segments appears multiple times in a single program, or is used in several programs. We can extract this group of program segments, name them, and store them separately; this group of program segments is called a subroutine. A subroutine is a machining program segment that can be called by appropriate machine tool control instructions, and it generally has independent meaning during machining. The machining program containing the instruction to call the first-level subroutine is called the main program. The instruction to call a subroutine is also a program segment, which generally consists of the subroutine call instruction, the subroutine name, and the number of calls. The specific rules and formats vary depending on the system. For example, for the same instruction "call subroutine number 55 once," the FANUC system uses "M98 P55.", while the American AB system uses "P55x."

 

Subroutines can be nested, that is, one level inside another. The relationship between the upper and lower levels is the same as the relationship between the main program and the first-level subroutine. The maximum number of nested levels is determined by the specific CNC system. The form and composition of a subroutine are largely the same as those of the main program: the first line is the subroutine number (name), and the last line is the "subroutine end" instruction, with the subroutine body in between. However, the main program end instruction terminates the main program and resets the CNC system; its instructions are standardized, with each system using M02 or M30. The subroutine end instruction, on the other hand, terminates the subroutine and returns to the main program or the previous subroutine. Its instructions vary across systems; for example, FANUC systems use M99, Siemens systems use M17, and AB (American A/B) systems use M02.

Send Inquiry