8051 Instruction set-4
R. Theagarajan. ME., MSc., PhD Rtd. Professor in Engineering email: rtheagarajan@yahoo.com rtrajan59@gmail.com
Instruction Set 5 groups
Data Transfer group Arithmetic operation group Logical operation group Boolean variable manipulation Program & Machine control
Branching Group If the indicated bit is 1, jump to the given address 3 JB bit, label No flags are affected JB Acc.5, Top JB P1.2, Sun
If the indicated bit is 0, jump to the given address, otherwise proceed with next instruction 3 JNB bit, label JNB Acc.3, Top JNB
P2.5, Sun
Branching Group If the indicated bit is 1, jump to the given address, otherwise proceed with next instruction and clear the specified bit 3
JBC bit, label JBC Acc.3, Top
Branching Group If the Cy flag is set, branch to the given address No flags are affected 2 JC label JC
Top
(PC)
(PC) + rel. address
If the Cy flag is 0, branch to the given address, otherwise proceed with next instruction 2 JNC label JNC
Top
(PC)
(PC) + rel. addres
Branching Group If the Accumulator is 0, branch to the given address No flags are affected 2 JZ label JZ
Top
(PC)
(PC) + rel. address
If the Acc. is not 0, branch to the given address, otherwise proceed with next instruction 2 JNZ label JNZ
Top
(PC)
(PC) + rel. address
Branching Group Jump indirect Add the eight bit unsigned content of Acc. with the data pointer and load the resulting sum to the program counter. Accumulator and Data pointer content is not altered. No flags are affected.
1
JMP @DPTR+A
Branching Group Absolute Call Unconditionally calls a subroutine. Before calling, it pushes the address of the next instruction to be executed into the stack memory. The destination address is obtained from op-code bits 7-5 and second byte of the instruction. The called subroutine must therefore start within the same 2K block. No flags are affected
2
ACALL ACALL
addr11 Ram
Branching Group Long Call Unconditionally calls a subroutine. Before calling it pushes the address of the next instruction to be executed into the stack memory. Then the PC is loaded with called subroutine address. The subroutine may be anywhere in the 64K program memory address. No flags are affected 3
LCALL label LCALL
Rajan
Branching Group Short Jump Unconditionally branches to the address specified. The branch address is computed by adding the signed displacement in the second instruction byte to the PC. The range of destination allowed is from 128 bytes preceding this instruction to 127 bytes following it. No other flags are affected
2
SJMP relative address SJMP
Rajan
Branching Group Absolute Jump Transfers program execution to the indicated address. The destination address is obtained from op-code bits 7-5 and second byte of the instruction. The destination must therefore be within the same 2K block. No flags are affected
2
AJMP addr11 AJMP Rajan
Branching Group Long Jump Unconditionally branches to the specified address. The PC is loaded with second and third instruction bytes. The destination may be anywhere in the 64K program memory address. No flags are affected 3
LJMP addr16 LJMP
Rajan
Branching Group Return from the subroutine. Last instruction of the called subroutine must be RET. It pops the address from the stack into the PC. 1 RET
Return from the Interrupt subroutine. Last instruction of the called interrupt subroutine must be RETI. It pops the address from the stack into the PC. Restores the interrupt logic to accept additional interrupts at the same priority level. 1 RETI
Branching Group Compare the magnitudes of the first two operands and branch if Not Equal. The destination is computed by adding the signed relative displacement to the PC. The carry flag is set if the unsigned integer value of destination byte is less than the unsigned integer value of source. Otherwise Cy flag is cleared. Neither operand is affected
3
CJNE A, direct, label CJNE A, 50h, Top Wait: CJNE A, P1, wait
Branching Group Compare the magnitudes of the first two operands and branch if Not Equal. The destination is computed by adding the signed relative displacement to the PC. The carry flag is set if the unsigned integer value of destination byte is less than the unsigned integer value of source. Otherwise Cy flag is cleared. Neither operand is affected
3
CJNE A, #data, label CJNE A, #50h, Top Wait: CJNE A, #50h, wait
Branching Group Compare the magnitudes of the first two operands and branch if Not Equal. The destination is computed by adding the signed relative displacement to the PC. The carry flag is set if the unsigned integer value of destination byte is less than the unsigned integer value of source. Otherwise Cy flag is cleared. Neither operand is affected
3
CJNE Rn, #data, label CJNE R5, #50h, Top
Branching Group Compare the magnitudes of the first two operands and branch if Not Equal. The destination is computed by adding the signed relative displacement to the PC. The carry flag is set if the unsigned integer value of destination byte is less than the unsigned integer value of source. Otherwise Cy flag is cleared. Neither operand is affected
3
CJNE @Ri, #data, label CJNE @R0, #50h, Rajan
Branching Group Decrement the location indicated by 1, and branch to the address indicated by the second operand if the resulting value is not zero. No flags are affected
3
DJNZ Rn, label DJNZ R0, Rajan DJNZ direct, label DJNZ 40h, Top
Branching Group 1
NOP
No operation. Execution continues to the next instruction. Other than PC, no registers or flags are affected. CLR P2.5
NOP NOP NOP NOP SETB P2.5
It will generate low going pulse lasting for 5 cycle
Avoid Plastics Plant a Tree Let us take care of our earth for future generation