It depends a lot on your control as to the format for calling up and running a sub routine.
On a Fanuc control you would have your subprogram numbered like O2300, and your main program like O230.
In your main program when you want to run your sub routine you call up your sub by inserting an M98P02300, at the end of your sub you need the line M99 instead of the normal M02 or M30 so it knows to jump back into the main program where it left off. That's it in a nutshell. Very simple to impliment so long as you know the format required of your machining center.