Browse
 
Tools
Rss Categories

Comparison: CALL vs CALLS TML instructions [II]

Author: AM Reference Number: AA-00492 Views: 5912 Created: 04-05-2016 11:18 Last Updated: 03-06-2016 18:47 0 Rating/ Voters

There are 2 types of function calls that can be made using TML and TML_Lib as well: CALL and CALLS.

- CALL - This instruction is a simple function call. At the execution of the CALL instruction, the TML machine will save the instruction pointer (IP) on the TML stack. This will be used as a return address when the RET (return from function) instruction is executed (the RET instruction must be present at the end of each and every function - EasyMotion Studio automatically adds RET at the end of every function that is defined in the Functions dialogue).

Remarks:
1) A function can be called from within another function, but the number of subsequent calls that can be performed is limited to 11, as the TML stack is 11 levels deep. If this limit is exceeded the drive will return the "TML stack overflow error" (DER register, bit 0 will be set) along with "Command error" (MER register, bit 14 will be set);
2) Care must be taken in order not to jump out of a function using "GOTO" instructions!

- CALLS - This instruction is a cancellable call. It is a special kind of call where, in addition to the usual save of the instruction pointer (IP) on the TML stack, the return address is also independently saved for future retrieval of the ABORT instruction. That is why a function that is called using CALLS can be cancelled / aborted irrespective of how many "normal" function calls are subsequently made. This also means that at one time, only one function can be called using the CALLS mechanism.

Remark:
The instructions "HOMING x" and "FUNCTION x" are also treated like a CALLS instruction.

The difference between CALL and CALLS is actually visible only when there are nested function calls. A chain like "CALL function1", which in turn executes "CALL function2", which then executes "CALL function3" can be finished only by executing RET (return from function) instruction 3 times (first time function3 is finished, then function2 and finally function1 is finished and the TML program flow is back where it was when the first CALL function1 was executed).

On the other hand a chain like "CALLS function1", which in turn executes "CALL function2", which then executes "CALL function3" can be finished just like in the above case or it can be abruptly finished using the ABORT instruction. When the ABORT instruction is executed, the TML program will automatically return to where it was when the CALLS instruction was executed. Basically any subsequent functions that were active will be forcefully cancelled. This is useful in situations that require cancelling of every function from a chain.

Remark: The location of CALLS in a nested chain of functions is not relevant - there can be something like CALL, CALL, CALLS, CALL, CALL (and in this case ABORT will cancel the last 3 functions and will automatically return to the 2nd function - 2nd CALL) or there can be something like CALLS, CALL, CALL, CALL. In this case ABORT will cancel all active functions.

Rss Comments
  • There are no comments for this article.