ELECTRONICS-DSC -1005 D Semester: IV Electronics-
Paper- IV Advance Communication and
Microcontroller 8051
Section II: Microcontroller 8051
Unit 2: Instruction Set of 8051
Classification of instruction sets, Addressing modes .
Instruction set of 8051: data transfer, arithmetic, Logical, Jump, call,
Boolean instructions.
Addressing modes:-
The ways to specify the address of data in instruction is called
addressing modes. The data could be in a register, or in memory, or be
provided as an immediate value. There are four addressing modes.
1) Immediate addressing mode
2) Direct addressing mode
3) Register addressing modes
4) Indirect addressing modes (indirect register addressing mode)
5) Indexed addressing mode
Immediate addressing mode:-
In this instruction data is directly written in the instruction. i.e. data is a part of instruction.
1)MOV A, #data (MOV A, #55)→ copy specified data into accumulator.
2)MOV Rn, #data(MOV R0,#22H )→copy specified data into Register(R0-R7).
3)ADD A, #data→ Adds the specified data with content of accumulator.
4)SUBB A, #data→ Subtract the specified data with the content of accumulator.
5)ORL A, #data→ The specified data is ORed with the content of accumulator.
6)MOV DPTR,#16bit data→ Copy the 16-bit data into DPTR. e.g. MOV DPTR, #9006.
Direct Addressing mode:-
All 128 bytes of internal RAM & SFR`S can be addressed using assigned values. In this instruction, the address of
operands are directly specified.
1)MOV A, add→ Copy data from location specified by given address into Accumulator.
A)MOV A, 80H ;Read the content of port P0(add 80H) & copy them into Acc.
B)MOV 80H, A ;write into port P0.
C)MOV PSW, A (move D0,E0); Move the content of Acc. Into flags.
2)MOV Rn, add→ Copy data from locations specified by given address into register Rn.
e.g.MOV R2,12H ; copy data from location specified by 12h into R2.
3)Add Address→ Adds the data from the location specified by given address with the content of accumulator.
4)XCH A, Address→ Exchange the data from the location specified by given address with the content of accumulator.
5)XRL A, address→ The data from the location specified by given address is XORed with the content of accumulator.
Register Addressing mode:-
In register addressing mode, the register A(accumulator), R0-R7 are specified in the instruction itself.
(R0-R7) are used in currently selected bank.
e.g. 1)MOV A, R0; Move data from register R0 to A A←R If R0=55H then A=55H
2)MOV A, Rn ; A←Rn.
3)ADD A, Rn ; Adds the content of register Rn with Accumulator.
4)SUBB A, Rn; Subtracts the contents of register Rn from Acc with Borrow.
5)XRL A, Rn ; The contents of register Rn are XOred with accumulator content.
6)XCH A, Rn ; The content of register Rn & Acc are exchanged.
7)ANL A, Rn ; The content of register Rn are ANDed with accumulator.
8)ADDC A, Rn; The content of Rn are added into Accumulator with carry movement of
data between register. Rn is not allowed i.e. MOV R5, R6 is not valid (only R0,R1 are used as pointer
register )
Indirect (Register)addressing mode:-
In this addressing mode, register is used to hold the actual address of operand or data. The register itself
is not the address. These instructions uses R0, R1 as data pointer and register, but R2-R7 are not allowed
to hold address.
1)MOV A, @Ro ; Move to accumulator content of memory location pointed by reg. R0
2)MOV @R1, A; move the content of the accumulator into memory location pointed by register R1.
3)ADD A,@R0; Adds the content of memory location pointed b register R0 with content of accumulator
4)SUB A,@R1; Subtracts the content of memory location pointed out by register R1 from contents of
accumulator.
5)INC @R0; increment the contents of memory location pointed out by register R0.
6)DEC @R1;Decrement the contents of memory location pointed by regsiter.
7)ANL A,@R; The content of memory location pointed out by reg R1 is ANDed with content of
accumulator. But, MOV A,@R3;This is not valid.
Indexed addressing mode( External addressing mode):-
It is widely used in accessing data elements of look-up table entries located in the program
ROM.
•MOVC A,@A+DPTR : Here MOVC, “C” means code. The contents of A are added to the
16-bit register DPTR to form the 16-bit address from which data is copied into A.
•MOVC A,@A+PC : The contents of A are added to the 16-bit register PC to form the 16-bit
address from which data is copied into A.
2.1 Addressing modes
When controller executes an instruction, it perform the
specific function on data. The different ways to specify the
address of data in an instruction are called as addressing
modes.
2.1.1 Types of Addressing Modes
•Direct addressing mode
•Register Indirect addressing mode
•Register addressing mode
•Immediate addressing mode
•Indexed / External addressing mode
•Direct addressing mode
In this mode the operand is specified by an 8 bit
address field in the instruction .Internal RAM and all
SFRs can be accessed by direct addressing mode. The
internal memory address from 00H to 7FH and the SFRs
can access from 80H to FFH
e.g. MOV A, 60H ; copy the content of memory location 60H
to register A
•Register Indirect addressing mode
In this addressing mode, the instruction
specifies the register which contains the address of an
operand. The registers from the register bank are used as a
memory pointer . The @ sign indicated the register acts as a
pointer to memory location. Only R0 and R1 registers are used as
pointers for selected bank.
e.g. MOV A,@R0 ; copy the content of the memory location whose
address id pointed by register R0
• Register addressing mode
In this addressing mode the operand is copied from
one register to another register. In this addressing mode both
source and destination are registers.
e.g. MOV A, R0 ; copy the content of R0 to register A
•Immediate addressing mode
This method is the simplest method to transfer a data.
In this addressing mode the operand/data is the part of
instruction. The # sign indicates that the data followed
immediate by operand.
e.g. MOV A,#20H ; copy the immediate data to
register A
•Indexed/External addressing mode
Using this addressing mode only external program memory
can be accessed. This addressing mode is used to read the
lookup table. Either the DPTR or PC is used as a memory
pointer.
e.g. MOVC A,@A+DPTR ; copy the content of
memory location to register A pointed by DPTR register
The 8051 instruction set is divided into different
groups
1. Data Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Bit Processing Instructions
5. Program Branching Instructions
1. Data Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions :
4. Bit Manipulation Instructions
Single bit Jump Instructions
addressing No.of
Mnemonics operation Example Description
mode bytes
jump to
JB bit, rel address Direct 3 JB P1.5, HERE jump if bit P1.5 is set
target
jump to JNB ACC.0,
JNB bit,rel address Direct 3 jump if bit ACC.0 not set
target NEXT
jump to JBC ACC.7, jump if bit ACC.7is set and
JBC bit, rel address Direct 3
target NEXT clear bit
jump to
JC, rel address Direct 3 JC NEXT Jump if Carry is set
target
jump to
JNC, rel address Direct 3 JNC NEXT Jump if Carry not set
target
5. Program Branching Instructions:
Branching instructions are classified into the two
groups:
1. Jump instructions
2. Subroutine instructions
Jump instructions
a. Short relative jump
b. Absolute jump
c. Long jump
Short relative jump
Absolute jump:
AJMP <11 bit address>
The Absolute jump is two byte unconditional jump. It jumps within page of 2K byte. In
8051, 64 Kbyte of program memory space is divided into 32 pages of 2Kbyte each.
Long Jump : (long jump)
LJMP <16 bit address>
It is used to access the entire program memory from 0000H to FFFFH. It is a 3-byte
instruction (except for JMP @ A+DPTR). First byte is the op-code and second and third
bytes represent the 16-bit target address which is any memory location from 0000 to
FFFFH. eg: LJMP 7000H
Subroutine Instructions
In the 8051 a subroutines are handled by CALL and RET instructions. The main
difference between CALL and JUMP instructions is that CALL has return path and jump
has no return path. When CALL instructions are executed then the content of the PC
pointed to the next of the CALL is stored into the stack pointer. During RET instructions
it is loaded into the PC.
There are two types of CALL instructions
a. Absolute call : ACALL
b. Long call : LCALL
Absolute call
ACALL <11 bit address>
The Absolute CALL is two byte call instruction. It call within page of 2K byte. In 8051, 64
Kbyte of program memory space is divided into 32 pages of 2Kbyte each.
Long CALL
LCALL <16 bit address>
This is long call instruction which unconditionally calls the subroutine located at the
indicated 16 bit address. This is a 3 byte instruction. No flags are affected. e.g.
LCALL 7000H
RET instruction
A RET instruction pops top two content from the stack memory and loaded into PC.
After execution of RET instruction a main program is executed. e.g. RET