Make your own stack if you want one.
Originally Posted by
Andre' B
It is possible that on some machines they may retain values from the last time the sub was called.
But since they are local to the (level) of the sub call and not the sub itself and for just good progamming practice (regardless of the programming language) it would be a bad idea to assume it will always be true.
Edit : So you should always set a local variable to a known value either in the line calling the sub or within the sub itself.
I wish the macro sub calls used a stack system rather then that fixed number of levels.
Note: THIS SHOULD WORK IN Mach3, but I know nothing about Fanuc Syntax.
Lets say our stack is at #1000
Let #996 to #999 be temporary X,Y,Z,A variables that can be destroyed by a call.
Let #99 be our index.
(start of program)
#99 = 0
(set up #996 to #999 here if you need to)
call subroutines, and you can nest them if you want.
M30 (end of program)
(---------------------)
O1234 (subroutine label)
(subroutine with X,Y,Z and A in #996,#997,#998 and #999)
#99 = #99 + 4 (first lline)
(access private stack)
#[1000 + #99] = #996 (save X value)
#[1001 + #99] = #997 (save Y value)
#[1002 + #99] = #998 (save Z value)
#[1003 + #99] = #999 (save A value)
G1 X[#996] Y[#997] Z[#998] A[#999]
(more G-Code)
(other calls)
#997 = 0 (you can destroy this if you want)
(other calls)
#99 = #99 - 4 (restore on exit this subroutine level)
M99 (return)
(end subroutine)
Other subroutines called will have their own private stack if use the #99 calling and exit convention.
Super X3. 3600rpm. Sheridan 6"x24" Lathe + more. Three ways to fix things: The right way, the other way, and maybe your way, which is possibly a faster wrong way.