Absolute Call – ACALL addr11
ACALL unconditionally calls a subroutine located at the indicated address. The instruction increments the Program Counter (PC) twice to obtain the address of the following instruction, then pushes the 16-bit result onto the stack (low-order byte first) and increments the Stack Pointer (SP) twice. The destination address is obtained by successively concatenating the five high-order bits of the incremented PC, opcode bits 7 through 5, and the second byte of the instruction. The subroutine called must therefore start within the same 2 K block of the program memory as the first byte of the instruction following ACALL. No flags are affected.
Encoding: a10 a9 a8 1 0 0 0 1 a7 a6 a5 a4 a3 a2 a1 a0
Initially SP equals 07H. The label SUBRTN is at program memory location 0345 H. After executing the following instruction,
ACALL SUBRTN
at location 0123H, SP contains 09H, internal RAM locations 08H and 09H will contain 25H and 01H, respectively, and the PC contains 0345H.
CALL instruction is used to call subroutines located in address space of the 8051. To make sure that after execution of the called subroutine the 8051 knows where to come back to, the processor automatically saves on the stack the address of the instruction immediately below the LCALL. When a subroutine is called, control is transferred to that subroutine, and the processor saves the PC (program counter) on the stack and begins to fetch instructions from the new location. After finishing execution of the subroutine, the instruction RET (return) transfers control back to the caller. Every subroutine needs RET as the last instruction.
Example:
ORG 0H
MAIN :
MOV A, #0AAH ; load A with AA
MOV P2, A ; send AA to port 2
LCALL TDELAY ; time delay
MOV A, #55H ; load A with 55
MOV P2, A ; send AA to port 2
ACALL TDELAY ; time delay
SJMP MAIN ; Keep doing this indefinitely
; Delay Subroutine
ORG 500H ; put time delay subroutine at program memory location 5000H
TDELAY : MOV R3, #0FFH ; initialize the counter
LOOP : DJNZ R3, LOOP ; stay her until r5 = 0
RET ; return to caller
END
Related topics:
8051 Long Call | 8051 Return from Subroutine and Interrupt | 8051 Long Jump | 8051 Absolute Jump | 8051 Short Jump | 8051 Indirect Jump
List of topics: 8051
No comments:
Post a Comment