Sei sulla pagina 1di 1

SUBROUTINE It is a group of instructions that performs a specified task.

It is written independent of a main program & can be called multiple times to perform that task whenever needed by the main program or by another subroutine. It save memory space. It includes CALL & RETURN instructions. When the MPU executes the CALL instruction, it stores the contents of the program counter, which is the address of the next instruction to the CALL, on the top of the stack & jumps to the subroutine location. When the MPU executes the RETURN instruction at the end of the subroutine, it finds the address on the top of the stack & jumps to that address. PIC18 CALL & RETURN Instructions The PIC18 instruction set includes two call instruction: 1) Two word instruction, capable of calling a subroutine anywhere in 2MB memory range. 2) One word relative CALL instruction that can call a subroutine within +-1k byte memory range. The set includes two RETURN instructions: 1) One is used with the above CALL instructions. 2) Returns an 8 bit number to the calling program that is used primarily in older medium to small sized versions of PIC family of microcontrollers.

Potrebbero piacerti anche