Addressing Modes
The way in which the instruction is specified.
• Immediate
• Register
• Direct
• Register Indirect
• Indexed
Friday, January 3, 2020
1. Immediate Addressing Mode
• Immediate Data is specified in the instruction itself
• The source operand is a constant number
• Values can be loaded directly into A, B, R0-R7
• To show it is an immediate value precede with a # sign
• Egs:
MOV A,#65H
MOV R3,#65H
MOV DPTR,#2343H
Friday, January 3, 2020
2. Register Addressing Mode
• It involves the use of registers to hold the data to be manipulated
• Register to register moves occurs between A and R0-R7
• One of the operand is accumulator
• Eg: MOV R0,A // copy the contents of A to R0
• MOV R1,A
• INVALID MOV R1,R2 - MOV A,R2
MOV R1,A
3. Direct Addressing Mode
In this addressing mode, data is in the RAM location whose address is
known and this address is directly given as part of the instruction
MOV R0, 40H // copy data from RAM location 40h to register R0
MOV 56H, A // copy value in A to RAM location 56h
MOV A,12H // copy data from RAM location 12h to A
Friday, January 3, 2020
4. Register Indirect Addressing Mode
• It uses a register to hold the actual address that will be used in the
data move
• Register itself is not the address but the content in the register
• Uses register R0 and R1 (called as data pointers)
• It holds the address of RAM locations from 00h to 7Fh
• For indirect addressing @ is used
eg: MOV A,@R0
copy the contents of the address specified in R0 to Accumulator
MOV@R1,A -----copy A to the address in R1
MOV @R0,80H ---Copy the contents of RAM location 80h to the
address in R0
Friday, January 3, 2020
Indexed Addressing Mode And On-Chip ROM Access
• This mode is widely used in accessing data elements of look-up table
entries located in the program (code) space ROM at the 8051
MOVC A,@A+DPTR
A= content of address A +DPTR from ROM
Note:
Because the data elements are stored in the program (code ) space
ROM of the 8051, it uses the instruction MOVC instead of MOV. The
“C” means code.
Friday, January 3, 2020
INSTRUCTION SET OF 8051
MARY CATHERINE
DEPT OF ECE
SSET
TYPES OF INSTRUCTIONS
DATA TRNSFER INSTRUCTIONS
ARITHMETIC INSTRUCTIONS
LOGICAL INSTRUCTIONL(S
JUMP AND CALL INSTRUCTIONS
BIT LEVEL (BOOLEAN) INSTRUCTIONS
DATA TRANSFER INSTRUCTIONS
MOV A, Rn register
MOV A, direct <- content of direct address
MOV A,@Ri <- content of address in Ri
MOV A,#data <- immediate data
DATA TRANSFER INSTRUCTIONS
MOV Rn,A Accumulator
MOV Rn, direct <- content of direct address
MOV direct,A <- accumulator
MOV Rn,#data <- immediate data
MOV direct,Rn <- contents of register
MOV direct,direct <- contents of direct address
DATA TRANSFER INSTRUCTIONS
MOV direct ,@Ri <- contents of address in Ri
MOV drect, #data <- immediate data to direct
MOV @Ri ,A <- acc to address in Ri
MOV @Ri, direct <- contents of direct address
to address in Ri
MOV @Ri,#data <- immediate data to
address in Ri
DATA TRANSFER INSTRUCTIONS
MOV DPTR,#16 bit data <- load data pointer with 16 bit
constant
MOVC A,@A+DPTR <- code byte at ROM address
formed by(A+DPTR)
MOVC A,@A+PC <- code byte at (A+PC)
It is an indirect addressing mode where the number in
register A is added to the pointing register to form address in
ROM where the desired data is to be found
DATA TRANSFER INSTRUCTIONS
MOVX A,@Ri <- contents of ext. address
Ri to accumulator
MOVX A,@DPTR <- contents of ext. address in
DPTR to accumulator
MOVX @Ri, A <- accumulator to ext. add
in Ri
MOVX @DPTR,A <- accumulator to
ext.address in DPTR
Data exchanges
Exchange instructions actually move data from Source to
Data / data to source
XCH A, Rn <exchange data bytes between A and Rn
XCH A, direct <exchange data bytes between A and address
XCH A, @Rn <exchange data bytes between A& content of address in Rn
XCHD A, @Rp <exchange lower nibbles between A and address in Rp
ARITHMETIC INSTRUCTIONS
ADD A, Rn <- add register to acc
ADD A,direct <- add contents of address to A
ADD A,@Ri <- add contents of address in Ri
to A
ADD A, #data <- add immediate data to A
ARITHMETIC INSTRUCTIONS
ADDC A, Rn <- add register to acc with
carry
ADDC A,direct <- add contents of address to
A with carry
ADDC A,@Ri <- add contents of address in
Ri to A with carry
ADDC A, #data <- add immediate data to A
with carry
ARITHMETIC INSTRUCTIONS
SUBB A, Rn <- subtract register from acc with
borrow
SUBB A,direct <-subtract contents of address
from A with borrow
SUBB A,@Ri <-subtract contents of address
in Ri from A with borrow
SUBB A, #data <- subtract immediate data
from A with borrow
ARITHMETIC INSTRUCTIONS
MUL AB <- multiply A & B; B:A
DIV AB <- divide A by B; quo in A,Rem: B
DAA <-decimal adjust after addition
for BCD Addition
ARITHMETIC INSTRUCTIONS
INC A <- increment accumulator
INC Rn <- increment register by 1
INC direct <- increment contents of address
INC @Ri <- increment contents of address in Ri
INC DPTR <- increment Data pointer
ARITHMETIC INSTRUCTIONS
DEC A <- decrement accumulator
DEC Rn <- decrement register by 1
DEC direct <- decrement contents of address
DEC @Ri <- decrement contents of address in
Ri
LOGICAL INSTRUCTIONS
ANL A,Rn <- AND register to accumulator
ANL A, direct <- AND contents of address to A
ANL A,@Ri <- AND contents of address in Ri
to accumulator
ANL A,#data <- AND immediate data to
accumulator
ANL direct,A <- AND accumulator to direct
byte
ANL direct,#data <-AND immediate data to direct byte
LOGICAL INSTRUCTIONS
ORL A,Rn <- OR register to accumulator
ORL A, direct <- OR contents of address to A
ORL A,@Ri <- OR contents of address in Ri to
accumulator
ORL A,#data <- OR immediate data to accumulator
ORL direct,A <- OR accumulator to direct byte
ORL direct,#data <-AND immediate data to direct byte
LOGICAL INSTRUCTIONS
XRL A,Rn <- XOR register to accumulator
XRL A, direct <- XOR contents of address to A
XRL A,@Ri <- XOR contents of address in Ri to
accumulator
XRL A,#data <- XOR immediate data to accumulator
XRL direct,A <- XOR accumulator to direct byte
XRL direct,#data <- XOR immediate data to direct byte
LOGICAL INSTRUCTIONS
CLR A <- clear accumulator
CPL A <- complement accumulator
RLA <- rotate accumulator left
RLC A <- rotate acc. left through carry
RRA <- rotate accumulator right
RRC A <- rotate acc. Right through carry
SWAP A <- swap nibbles within accumulator
ROTATE INSTRUCTIONS
BOOLEAN INSTRUCTIONS(BIT LEVEL)
CLR C <- clear carry
CLR Bit <- clear direct bit
SETB C <- set carry
SETB Bit <- set direct bit
CPL C <- complement carry
CPL bit <- complement direct bit
BOOLEAN INSTRUCTIONS(BIT LEVEL)
ANL C,bit <- AND carry to direct bit
ANL C,/Bit <- AND carry to complement of bit
ORL C,Bit <- OR carry to direct bit
ORL C,/Bit <- OR carry to complement of bit
MOV C,Bit <- move direct bit to carry
MOV Bit,C <- move carry to direct bit
BOOLEAN INSTRUCTIONS(BIT LEVEL)
JC label <- jump if carry set to label
JNC label <- jump if carry=0 to label
JB bit , label <- jump if bit is set to label
JNB Bit, label <- jump if bit not set to label
JBC Bit, label <-jump if bit set to label and clear bit
PROGRAM BRANCHING ISTRUCTIONS
JUMP AND CALL INSTRUCTIONS
JUMPS ARE OF 3 TYPES
1. SHORT JUMP (SJMP)
2. LONG JUMP(LJMP)
3. ABSOLUTE JUMP(AJMP)
TYPES OF JUMPS
SHORT JUMP(SJMP)
TRANSFERS CONTROL WITHIN 256 BYTES
-128 TO +127 BYTES
EG: SJMP Label
TYPES OF JUMPS
ABSOLUTE JUMP(AJMP)
TRANSFERS CONTROL WITHIN 2KB
EG: AJMP 11 Bit address
TYPES OF JUMPS
LONG JUMP(LJMP)
TRANSFERS CONTROL WITHIN 64KB
EG: LJMP 16 Bit address
CALL INSTRUCTIONS
TYPES OF CALL
ABSOLUTE CALL(ACALL)
LONG CALL(LCALL)
CALL INSTRUCTIONS
ACALL 11 BIT ADDRESS
CALLING A SUBROUTINE WITHIN 2KB OF PROGRAM
MEMORY
CALL INSTRUCTIONS
LCALL 16 BIT ADDRESS
CALLING A SUBROUTINE WITHIN 64KB OF PROGRAM
MEMORY
CONDITIONAL JUMPS
JZ LABEL ; JUMP IF ACCUMULATOR IS ZERO
JNZ LABEL ;JUMP IF ACCUMULATOR IS NON
ZERO
DJNZ Rn , label ; decrement the register and jump
to label if non zero
DJNZ direct, label ; decrement direct byte and jump
to label if non zero
CJNE INSTRUCTION
CJNE INSTRUCTION COMPARES THE FIRST OPERAND WITH
2ND OPERAND AND PERFORMS BRANCH OPERATION IF NOT
EQUAL
CJNE INSTRUCTION
CJNE A, direct , label ; compare direct byte to acc &
jump if not equal
CJNE A, #data , label ; compare immediate data to acc
& jump if not equal
CJNE Rn, #data , label ;compare Rn with immediate data
CJNE @Ri , #data, label; compare imm data with indirect
byte and jump if not equal
RETURN INSTRUCTIONS
RET - RETURN FROM SUBROUTINE
RETI – RETURN FROM INTERRUPT
NOP – NO OPERATION
PUSH & POP instructions
PUSH & POP opcodes specifies the direct address of the data
It is a data move instruction from stack to the specified address
Register associated is Stack pointer – contains the internal RAM address where the data
will be pushed
PUSH & POP instructions
PUSH address :
Increment SP by 1 ; SP = SP+1
Copy the address specified in the instruction to the
internal RAM address in SP register
By default SP is set to 07 H (R7 of bank 0)
Eg: PUSH 40H
It would push the data to the address 08H
POP instruction
POP address :
Copy the data from internal RAM address contained in SP
to address specified in the instruction
decrement SP by 1 ; SP = SP-1
E.g.: POP 40H
It would pop the data from the address 08H to the
address 40H
PUSH & POP
SP reaches FF it rolls over to 00H
RAM ends at address 7F H , PUSH es above 7F H result in
errors
PROGRAMS – ADDITION WITH CARRY
ORG 00H // origin
MOV R3, #00H // carry register initialised to 0
MOV A,40H // copy 1ST number from 40H to A
ADD A,41H // add a and content of 41H
JNC L1 // jump if no carry to label L1
INC R3 // Increment carry register by 1
L1: MOV 60H, A // copy result (sum) to address 60H
MOV 61H,R3 //copy result (carry) to address 61H
END // program ends
PROGRAMS – SUBTRACTION WITH BORROW
ORG 00H // origin
MOV R3, #00H // carry register initialised to 0
MOV A,40H // copy 1ST number from 40H to A
SUBB A,41H // Subtract a and content of 41H
JNC L1 // jump if no carry to label L1
INC R3 // Increment carry register by 1
CPL A // take 2’s Complement of the no
ADD A, #01H (1’s complement +1)
L1: MOV 60H, A // copy result to address 60H
MOV 61H,R3 //copy result (borrow) to address 61H
END // program ends
PROGRAMS – MULTIPLICATION OF TWO 8
BIT NOS
ORG 00H // origin
MOV A,40H // copy 1ST number from 40H to A
MOV B,41H // Copy content of 41H to B
MUL AB // multiply A and B
MOV 60H, A // copy result(LSB) to address 60H
MOV 61H,B //copy result (MSB) to address 61H
END // program ends
PROGRAMS – DIVISION OF TWO 8 BIT NOS
ORG 00H // origin
MOV A,40H // copy 1ST number from 40H to A
MOV B,41H // Copy content of 41H to B
DIV AB // divide A by B
MOV 60H, A // copy result(quotient) to address 60H
MOV 61H,B //copy result (remainder) to address 61H
END // program ends
PROGRAMS – ADDITION OF N NOS WITH
CARRY
ORG 00H // origin
MOV R3, #00H // carry register initialised to 0
MOV R2, 40H // R2 is the count register, copy contents of 40h TO R2
MOV R0,#41H // pointing array location to 41H
MOV A,@R0 //copy contents of address in R0 to A
INC R0 // increment R0
L2: ADD A, @R0 // add a and content of address specified in R0
JNC L1 // jump if no carry to label L1
INC R3 // Increment carry register by 1
L1: INC R0 //increment R0 by 1
DJNZ R2,L2 // decrement and jump if nonzero R2, to label L2
MOV 60H, A // copy result (sum) to address 60H
MOV 61H,R3 //copy result (carry) to address 61H