menu_top_normal
NeoLoch Home Page
Home Inquisitor Tester Learning Lab Consulting Shipping Policy Contact us Support ----------------------
News
Coming soon! 9060 Blade.
CALL Command:
Syntax:
Status Flags Effected:
CALL
CALL k
NONE
The CALL command is used to jump to a subroutine and then return when the code has completed execution. The return is accomplished by including either the RETLW or RETURN commands.

When the CALL command is executed, the return address is pushed onto the internal stack and then the program jumps to the address specified in the CALL command. When the RETURN command is encountered, the return address is poped from the stack and the program returns to the instruction immediately after the CALL command.

Code Example 1: Assume we have a section of code labeled DO_SOMETHING, the following example illustrates how to use the CALL command to call this subroutine
CALL     DO_THIS
GOTO     $-1

DO_THIS
RETLW    '"1"
Call the subroutine labeled DO_THIS.
Goto the instruction prior to this one. This effectively creates an endless loop.
Label for the subroutine DO_THIS.
Return from the CALL with the ascii value of "1" in the w register.

It's important to note that different families of microcontrollers have different size stacks. The base family of microcontrollers only have a 2 level deep stack. This means you can't execute more than two calls at any single one time, a call past this limit will destroy the deepest level return address and send the program into an unstable state.

The mid-range microcontrollers have an 8 level deep hardware stack allowing for much more deep call structures. And the higher end microcontrollers have 16 or higher deep hardware stacks.

For specifics on the microcontroller you are using refer to the datasheet for that MCU.

RETLW Command:
Syntax:
Status Flags Effected:
RETLW
RETLW k
NONE

RETLW simply returns the program to the command immediately after the CALL instruction with the value specified by 'k' in the working register. This command is very useful in creating data lookup tables. This command is available in all Microchip MCUs.


RETURN Command:
Syntax:
Status Flags Effected:
RETURN
RETURN
NONE

RETURN simple returns the program to the command immediately after the CALL instruction. The working register is not effected by this instruction. Be advised though this command is not supported by the base line of microcontrollers, if can be used in assembly program as it will simply be replaced with the RETLW command during the compile process.










All contents of this website are copyrighted 2010-2018 NeoLoch