Wednesday, March 23, 2016

8051 Long Call

Long Call – LCALL addr16

LCALL calls a subroutine located at the indicated address. The instruction adds three to the program counter to generate the address of the next instruction and then pushes the 16-bit result onto the stack (low byte first), incrementing the Stack Pointer by two. The high-order and low-order bytes of the PC are then loaded, respectively, with the second and third bytes of the LCALL instruction. Program execution continues with the instruction at this address. The subroutine may therefore begin anywhere in the full 64K byte program memory address space. No flags are affected.

Encoding: 0 0 0 1 0 0 1 0 addr15-addr8 addr7-addr0

Initially the Stack Pointer equals 07H. The label SUBRTN is assigned to program memory location 1234H. After executing the instruction,


at location 0123H, the Stack Pointer will contain 09H, internal RAM locations 08H and 09H will contain 26H and 01H, and the PC will contain 1234H.

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
LCALL 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

Related topics:
8051 Absolute 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