SlideShare a Scribd company logo
INSTRUCTION SET SUMMARY 8051
-1-
CHAPTER 3
INSTRUCTION SET SUMMARY
Structure of Assembly Language
[label:] Mnemonic [operands] [;comment]
LOOP: MOV A,#01H ; Write 1 to Acc
MOV R7,A ;(R7)  (A)
[PC] op code [operands] [ ]
8000H 74H 01H
8002H FFH
Figure 3.1 Structure of Assembly Language
Symbol Interpretation
 Is replaced by ….
( ) The contents of …
(( )) The data pointed at by ….
rrr One of 8 register; 000 = R0, 001 = R1, 010=R2,..etc
dddddddd Data bits
aaaaaaaa Address bits (byte address)
bbbbbbbb Address of a bit (bit address)
i Indirect addressing using R0 or R1
eeeeeeee 8-bit relative address (or offset)
Assembler
INSTRUCTION SET SUMMARY 8051
-2-
ADDRESSING MODES
Eight types addressing modes
• Register
• Direct
• Indirect
• Immediate
• Relative
• Absolute
• Long
• Indexed
Register Addressing
The 8051 assembly language indicates register addressing with the symbol Rn
where n is from 0 to 7.
Opcode n
Register Addressing
Examples:-
MOVRn,A ORL A,Rn
Bytes: 1 Bytes: 1
Cycle: 1 Cycle: 1
Encoding: 11111rrr Encoding: 01001rrr
Operation: (Rn)  (A) Operation: (A)  (A) OR (Rn)
Example: MOV R3,A Example: ORL A,R5
Encoding: 11111011 or FBH Encoding: 01001101 or 4DH
INSTRUCTION SET SUMMARY 8051
-3-
For instruction using register addressing, either the source or destination
operand contains a register.
Example
MOVA,R7
Bytes : 1
Cycles : 1
Encoding : 11101rrr
Operation : (A)  (Rn)
EFH. This instruction moves the 8-bit content of register 7 to the
accumulator.
There are 4 “banks” of working register –, address 00  1FH, but only one
is active at a time.
For Example:-
MOV PSW,#00011000B
PSW
BIT 7 BIT 0
Carry Aux. C Flag0 R.Bank 1 R. Bank 0 Overflow Reserved Even. P
CY AC F0 RS1 RS0 0V - P
RS1 RS0
0 0 bank 0; addresses 00H - 07H
0 1 bank 1: addresses 08H - 0FH
1 0 bank 2: addresses 10H - 17H
1 1 bank 3: addresses 18H – 1FH
Activates register bank 3 by setting the register bank select bits (RS1 and
RS0) in PSW bit positions 4 and 3.
Some instructions are specific to a certain register so address bits are not
needed. The opcode itself indicates the register.
For Example:-
INC DPTR ;(DPTR)  (DPTR) + 1
INSTRUCTION SET SUMMARY 8051
-4-
Is a 1-byte instruction that adds 1 to the 16-bit data pointer.
Example3-2
What is the opcode for the following instruction?
What does it do?
MUL AB
Opcode = A4H
Operation : (B)  HIGHBYTE OF (A) x (B)
(A)  LOWBYTE OF (A) x (B)
Direct Addressing
Direct addressing can access any on-chip variable or hardware register. An
additional byte is appended to the opcode specifying the location to be
used. Only internal RAM and SFRs can be directly accessed.
OPCODE
Direct address
Example:-
MOV P1,A ; (direct)  (A).
Opcode = 11110101
Direct Address = aaaaaaaa
Transfer the content of Acc to Port 1.
Using Appendix C as a reference the complete encoding of this instruction
is
11110101 – 1st
byte (opcode)
10010000 – 2nd
byte (address of P1)
INSTRUCTION SET SUMMARY 8051
-5-
Examples:-
MOV direct,A DEC direct
Bytes: 2 Bytes: 2
Cycle: 1 Cycle: 1
Encoding: 11110101 aaaaaaaa Encoding: 00010101 aaaaaaaa
Operation: (direct)  (A) Operation: (direct)  (direct) - 1
Example: MOV 20H,A Example: DEC B ; B is at 0F0H
Encoding: F5H 20H Encoding: 15H F0H
Moving data
MOV R5,A ; (R5)  (A)
MOV A,R0 ; (A)  (R0)
Logical operations
ANL A,R5 ; (A)  (A) AND (R5)
XRL R5,A ; (R5)  (R5) exOR (A)
Arithmetic Operation
ADD A,R3 ; (A)  (A) + (R3)
ADDC A,R3 ; (A)  (A) + (R3) + C
INSTRUCTION SET SUMMARY 8051
-6-
Indirect Addressing
The instruction specifies a register which contains the address of the
operand.
Opcode i
Examples:-
MOVX @Ri,A ADD A,@Ri
Bytes: 1 Bytes: 1
Cycle: 2 Cycle: 1
Encoding: 1111001i Encoding: 0010011i
Operation: ((Rn))  (A) Operation: (A)  (A) OR ((Ri))
Example: MOVX @R0,A Example: ADD A,@R1
Encoding: F2H Encoding: 27H
Example:-
MOV A,@R0
The Source is the memory location pointed by R0, the contents of which
are copied into the Accumulator which is the destination register.
MOV @R1,A
The Accumulator is the source and its contents are copied into the
destination which is the memory location pointed by R1.
Example:-
(a) What is the opcode for the following instruction?
(b) What does this instruction do?
MOV A,@R0
INSTRUCTION SET SUMMARY 8051
-7-
Solution
(a) E6H
(b) The instruction moves a byte of data from internal RAM to the
Accumulator. The data are moved from the location whose address is
in R0.
Examples:-
MOVX A,@DPTR MOVX @DPTR,A
Bytes: 1 Bytes: 1
Cycle: 2 Cycle: 2
Encoding: 1110000 Encoding: 11110000
Operation: (A)  ((DPTR)) Operation: ((DPTR))  (A)
Example:-
Moving data
MOV @R1,A ((R1))  (A)
MOV A,@R1 (A)  ((R0))
Logical Operation
ORL A,@R0 (A)  (A) OR ((R0))
XRL @R1,A ((R1))  ((R1)) exOR (A)
Arithmetic Operation
ADD A,@R0 (A)  (A) + ((R0))
ADDC A,@R1 (A)  (A) + ((R1)) + C
Immediate Addressing
The destination register is loaded with a constant value immediately.
Opcode
Immediate
data
INSTRUCTION SET SUMMARY 8051
-8-
Examples:-
ANL A,#data MOV DPTR,#DATA16
Bytes: 2 Bytes: 3
Cycle: 1 Cycle: 2
Encoding: 01010100 dddddddd Encoding: 10010000 dddddddd dddddddd
Operation: (A)  (A) AND #data Operation: (DPTR)  #data16
Example: ANL A,#0F0H Example: MOV DPTR,#2800H
Encoding: 54H F0H Encoding: 90H 28H 00H
Example:-
MOV A,#12
Loads the value of 12 into the Accumulator.
Moving data
MOV A,#F1H ; (A)  F1H
MOV R3,#C1H ; (R3)  1CH
Arithmetic Operation
ADD A,#10H ; (A) (A) + 10H
ADDC A,#10H ; (A) (A) + 10H + C
Logical operation
ORL A,#33H ; (A) (A) OR 33H
ANL A,88H ; (15H)  (15H) AND 88H
INSTRUCTION SET SUMMARY 8051
-9-
Relative Addressing
Relative Addressing is used only with certain jump instruction. A relative
address or offset is an 8-bit signed value, which is added to the program
counter to form the address of the next instruction executed. Range -128 to
+127 locations.
Opcode
Relative
Offset
Example :- SJMP THERE
THERE: MOV A,R1
ADD A,@R0
:
:
SJMP THERE
010A
0109
0108
0107 Relative offset from
Address 0102H
is “5”
0101 05 SJMP
0100 80 0107H
00FF
Code
Memory
SJMP is in memory location 0100H and
Offset is in the memory location 0101H.
Destination = PC + offset
= 0102 + 5
INSTRUCTION SET SUMMARY 8051
-10-
= 0107H
Example:-
The instruction SJMP 9030H is in the memory location
9000H and 9001H. What are the machine language bytes for this
instruction?
80H, 2EH
Destination = 9030H = PC + offset
Therefore, offset = destination – PC
= 9030H – 9002H
= 2EH
Example:-
JZ rel JB bit,rel
Bytes: 2 Bytes: 3
Cycle: 2 Cycle: 2
Encoding: 01100000 eeeeeeee Encoding: 00100000 bbbbbbbb eeeeeeee
Operation: Operation:
(PC)  (PC) + 2 (PC)  (PC) + 3
IF (A) = 0 IF (bit) = 1
Then (PC)  (PC) + byte_2 Then (PC)  (PC) + byte_3
Example:-
LABEL: MOV A,P1
ANL A,#1
JZ LABEL
MOV P0,P1
……
INSTRUCTION SET SUMMARY 8051
-11-
Absolute Addressing
This type of addressing mode is used only with ACALL and AJMP instruction.
These 2-byte instructions allow branching within the current 2K page of code
memory by providing the 11 least-significant bits of the destination address in
the opcode (A10-A8) and byte 2 of the instruction (A7-A0).
A10 – A8 Opcode
A7 A6 A5 A4 A3 A2 A1 A0
2 K page 31
:
:
:
2 K page 2
2 K page 1
2 K page 0
FFFFH
F800H
Within any
2 K page only
the lower 11
bits change OFFFH
0800H
07FFH
0000
INSTRUCTION SET SUMMARY 8051
-12-
Offers the advantage of short (2-byte) instructions, but has the
disadvantages of limiting the range for the destination and providing
position-dependent code.
If the label THERE represents an instruction at address 0F46H, and the
instruction
AJMP THERE
is in memory locations 0900H and 0901H, the assembler will encode the
instruction as
111 00001 - 1st
byte (A10 – A8 + opcode)
01000110 - 2nd
byte (A7 – A0)
0F46H = 0000 1111 0100 1110B
Example:-
An ACALL instruction is in memory locations 1024H and 1025H. The
subroutine to which the call is directed begins in memory location 17A6H.
What are the machine language bytes for the ACALL instruction?
Encoding for ACALL: aaa10001 aaaaaaaa
A15A14A13A12 A11A10A9A8 A7A6A5A4 A3A2A1A0
17A6H = 0 0 0 1 0 1 1 1 1 0 1 0 0 1 1 0
Therefore, 11110001 10100110 = F1H, A6H
INSTRUCTION SET SUMMARY 8051
-13-
Long Addressing
Long addressing is used only with the LCALL and LJMP instructions.
These 3-byte instruction include a full 16-bit destination address as bytes 2
and 3 of the instruction.
The 1st
byte – Opcode
2nd
and 3rd
- Destination Address.
Opcode
A15–A8
High byte add.
A7–A0
Low byte add.
The advantage is that the full 64K code space may be used, but the
disadvantage is that the instructions are 3 byte long and are position-
dependent.
Example:-
LJMP addr16 LCALL addr16
Bytes: 3 Bytes: 3
Cycle: 2 Cycle: 2
Encoding: Encoding:
00000010 aaaaaaaa aaaaaaaa 00010010 aaaaaaaa aaaaaaaa
Operation: Operation:
(PC)  addr16 (PC)  (PC) + 3,
(SP)  (SP) + 1, ((SP))  (PCL),
(SP)  (SP) + 1, ((SP))  (PCH),
(PC)  addr16
Example:-
What are the machine language bytes for the following instruction?
LJMP 8AF2H
Opcode High Byte Add. Low Byte Add.
Encoding :- 00000010 aaaaaaaa aaaaaaaa
Hence, the machine language bytes are 02H, 8AH,F2H
INSTRUCTION SET SUMMARY 8051
-14-
Indexed Addressing
Indexed Addressing uses a base register(either the PC or the data pointer)
and an offset(Accumulator) in forming the effective address for a JMP or
MOVC instruction.
Opcode
Jump tables or look-up tables are easily created using indexed addressing.
Examples:-
MOVC A,@A+<base-reg>
and
JMP @A+DPTR
Example: What is the opcode for the following instruction?
MOVC A,@A+DPTR
Solution: 93 H
Example:-
REL_PC: INC A ;(A) <- (A) + 1
MOVC A,@A+PC
RET
DB 66H
DB 77H
DB 88H
DB 99H
If The subroutine is called with the accumulator equal to 01H, it returns
with 77H in the accumulator. See Appendix C page 273 for further
information.
INSTRUCTION SET SUMMARY 8051
-15-
Example:-
Write a program to display 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 continuously through
Port1. Insert some delay between each displayed digit.
Display Common-Anode Display Common-Anode
0 C0H A 88H
1 F9H b 83H
2 A4H C C6H
3 B0H d A1H
4 99H E 86H
5 92H F 8EH
6 82H
7 F8H
8 80H
9 98H
INSTRUCTION SET SUMMARY 8051
-16-
ORG 0H
ULANG: MOV P1,#0C0H
LCALL DELAY
MOV P1,#0F9H
LCALL DELAY
MOV P1,#0A4H
LCALL DELAY
-
-
-
SJMP ULANG
DELAY: MOV R5,#20H
AGAIN: MOV R6,#255
LOOP1: MOV R7,#0F0H
LOOP: DJNZ R7,LOOP
DJNZ R6,LOOP1
DJNZ R5,AGAIN
RET
END
OR
INSTRUCTION SET SUMMARY 8051
-17-
ORG 0000H
ULANG: CLR A
MOV R0,A
MOV DPTR,#NOMBO
TAMBAH: MOV A,R0
MOVC A,@A+DPTR
MOV P1,A
LCALL DELAY
INC R0
CJNE R0,#11,TAMBAH
SJMP ULANG
DELAY: MOV R5,#10
LOOP2: MOV R6,#255
LOOP1: MOV R7,#255
LOOP: DJNZ R7,LOOP
DJNZ R6,LOOP1
DJNZ R5,LOOP2
RET
NOMBO: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,98H
END

More Related Content

PDF
8051 instruction set
PPTX
Instruction set of 8085 Microprocessor By Er. Swapnil Kaware
PDF
Introduction to 8085 by adi ppt
PPT
Data transfer instruction set of 8085 micro processor
PDF
INTEL 8085 DATA FORMAT AND INSTRUCTIONS
PPTX
Microprocessor instructions
PPT
Instruction set-of-8085
8051 instruction set
Instruction set of 8085 Microprocessor By Er. Swapnil Kaware
Introduction to 8085 by adi ppt
Data transfer instruction set of 8085 micro processor
INTEL 8085 DATA FORMAT AND INSTRUCTIONS
Microprocessor instructions
Instruction set-of-8085

What's hot (18)

PPTX
The 8051 microcontroller
PPT
The 8051 assembly language
PPT
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
PPT
Microcontroller instruction set
PPT
8085 instruction set (detailed)
PPT
1347 Assembly Language Programming Of 8051
PPT
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
PPTX
Stacks & subroutines 1
PPT
Instruction Set 8085
PPTX
Stack in microprocessor 8085(presantation)
PPT
Programming with 8085
PPT
Logical instruction of 8085
PPT
8086-instruction-set-ppt
PPTX
Microprocessor 8086 instructions
PPT
Instruction set of 8085
PPT
8085 instruction-set
PPT
8051 addressing modes
The 8051 microcontroller
The 8051 assembly language
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
Microcontroller instruction set
8085 instruction set (detailed)
1347 Assembly Language Programming Of 8051
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
Stacks & subroutines 1
Instruction Set 8085
Stack in microprocessor 8085(presantation)
Programming with 8085
Logical instruction of 8085
8086-instruction-set-ppt
Microprocessor 8086 instructions
Instruction set of 8085
8085 instruction-set
8051 addressing modes
Ad

Viewers also liked (8)

PDF
Electromagnetic wave radiation and antennas
PDF
The basics of antenna arrays
PDF
48270042 biology-stpm-lower-6-chapter-1
PPT
Dynamics of multiple degree of freedom linear systems
PDF
Solution of skill Assessment Control Systems Engineering By Norman S.Nise 6t...
PPT
Control chap2
DOC
8051 Microcontroller Notes
PPT
Mechanical Vibrations all slides
Electromagnetic wave radiation and antennas
The basics of antenna arrays
48270042 biology-stpm-lower-6-chapter-1
Dynamics of multiple degree of freedom linear systems
Solution of skill Assessment Control Systems Engineering By Norman S.Nise 6t...
Control chap2
8051 Microcontroller Notes
Mechanical Vibrations all slides
Ad

Similar to Instruction set summary (20)

PPT
Instructions_introductionM2.1.about.microcontrollerppt
PPT
12 mt06ped008
PPT
PDF
VTU 4th Semester ECE dept Microcontroller lecture slides module 2
PDF
mca is a microcontroller and accmulator is a third year couse
PPTX
The 8051 microcontroller
PPTX
module-3.pptx
PPTX
2. Instruction Set.pptx huishiuhfuidhiuhdfuhdu
PPT
Addressing modes
PPT
Lecture_4__8051_Instruction_Set__Rv01.ppt
PDF
Lecture 4 (8051 instruction set) rv01
PPTX
Mastering Assembly Language: Programming with 8086
PPTX
8051 microcontroller
PPT
8051d.ppt microcontroller instruction set summary
PPT
Microcontroller 8051- soft.ppt
PPT
Microprocessor system - summarize
PDF
Microprocessor Part 3
PDF
unit5_8051_microcontroller presentation.pdf
PPT
MC-MODULE-2.ppt includes addressing modes , instruction set etc...
PPTX
Assembly language.pptx
Instructions_introductionM2.1.about.microcontrollerppt
12 mt06ped008
VTU 4th Semester ECE dept Microcontroller lecture slides module 2
mca is a microcontroller and accmulator is a third year couse
The 8051 microcontroller
module-3.pptx
2. Instruction Set.pptx huishiuhfuidhiuhdfuhdu
Addressing modes
Lecture_4__8051_Instruction_Set__Rv01.ppt
Lecture 4 (8051 instruction set) rv01
Mastering Assembly Language: Programming with 8086
8051 microcontroller
8051d.ppt microcontroller instruction set summary
Microcontroller 8051- soft.ppt
Microprocessor system - summarize
Microprocessor Part 3
unit5_8051_microcontroller presentation.pdf
MC-MODULE-2.ppt includes addressing modes , instruction set etc...
Assembly language.pptx

Recently uploaded (20)

PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPT
Project quality management in manufacturing
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPT
Mechanical Engineering MATERIALS Selection
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Construction Project Organization Group 2.pptx
PPTX
web development for engineering and engineering
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Well-logging-methods_new................
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
DOCX
573137875-Attendance-Management-System-original
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
R24 SURVEYING LAB MANUAL for civil enggi
Project quality management in manufacturing
Internet of Things (IOT) - A guide to understanding
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
OOP with Java - Java Introduction (Basics)
Mechanical Engineering MATERIALS Selection
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Foundation to blockchain - A guide to Blockchain Tech
Construction Project Organization Group 2.pptx
web development for engineering and engineering
CYBER-CRIMES AND SECURITY A guide to understanding
Well-logging-methods_new................
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
573137875-Attendance-Management-System-original
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
UNIT 4 Total Quality Management .pptx
bas. eng. economics group 4 presentation 1.pptx
Model Code of Practice - Construction Work - 21102022 .pdf

Instruction set summary

  • 1. INSTRUCTION SET SUMMARY 8051 -1- CHAPTER 3 INSTRUCTION SET SUMMARY Structure of Assembly Language [label:] Mnemonic [operands] [;comment] LOOP: MOV A,#01H ; Write 1 to Acc MOV R7,A ;(R7)  (A) [PC] op code [operands] [ ] 8000H 74H 01H 8002H FFH Figure 3.1 Structure of Assembly Language Symbol Interpretation  Is replaced by …. ( ) The contents of … (( )) The data pointed at by …. rrr One of 8 register; 000 = R0, 001 = R1, 010=R2,..etc dddddddd Data bits aaaaaaaa Address bits (byte address) bbbbbbbb Address of a bit (bit address) i Indirect addressing using R0 or R1 eeeeeeee 8-bit relative address (or offset) Assembler
  • 2. INSTRUCTION SET SUMMARY 8051 -2- ADDRESSING MODES Eight types addressing modes • Register • Direct • Indirect • Immediate • Relative • Absolute • Long • Indexed Register Addressing The 8051 assembly language indicates register addressing with the symbol Rn where n is from 0 to 7. Opcode n Register Addressing Examples:- MOVRn,A ORL A,Rn Bytes: 1 Bytes: 1 Cycle: 1 Cycle: 1 Encoding: 11111rrr Encoding: 01001rrr Operation: (Rn)  (A) Operation: (A)  (A) OR (Rn) Example: MOV R3,A Example: ORL A,R5 Encoding: 11111011 or FBH Encoding: 01001101 or 4DH
  • 3. INSTRUCTION SET SUMMARY 8051 -3- For instruction using register addressing, either the source or destination operand contains a register. Example MOVA,R7 Bytes : 1 Cycles : 1 Encoding : 11101rrr Operation : (A)  (Rn) EFH. This instruction moves the 8-bit content of register 7 to the accumulator. There are 4 “banks” of working register –, address 00  1FH, but only one is active at a time. For Example:- MOV PSW,#00011000B PSW BIT 7 BIT 0 Carry Aux. C Flag0 R.Bank 1 R. Bank 0 Overflow Reserved Even. P CY AC F0 RS1 RS0 0V - P RS1 RS0 0 0 bank 0; addresses 00H - 07H 0 1 bank 1: addresses 08H - 0FH 1 0 bank 2: addresses 10H - 17H 1 1 bank 3: addresses 18H – 1FH Activates register bank 3 by setting the register bank select bits (RS1 and RS0) in PSW bit positions 4 and 3. Some instructions are specific to a certain register so address bits are not needed. The opcode itself indicates the register. For Example:- INC DPTR ;(DPTR)  (DPTR) + 1
  • 4. INSTRUCTION SET SUMMARY 8051 -4- Is a 1-byte instruction that adds 1 to the 16-bit data pointer. Example3-2 What is the opcode for the following instruction? What does it do? MUL AB Opcode = A4H Operation : (B)  HIGHBYTE OF (A) x (B) (A)  LOWBYTE OF (A) x (B) Direct Addressing Direct addressing can access any on-chip variable or hardware register. An additional byte is appended to the opcode specifying the location to be used. Only internal RAM and SFRs can be directly accessed. OPCODE Direct address Example:- MOV P1,A ; (direct)  (A). Opcode = 11110101 Direct Address = aaaaaaaa Transfer the content of Acc to Port 1. Using Appendix C as a reference the complete encoding of this instruction is 11110101 – 1st byte (opcode) 10010000 – 2nd byte (address of P1)
  • 5. INSTRUCTION SET SUMMARY 8051 -5- Examples:- MOV direct,A DEC direct Bytes: 2 Bytes: 2 Cycle: 1 Cycle: 1 Encoding: 11110101 aaaaaaaa Encoding: 00010101 aaaaaaaa Operation: (direct)  (A) Operation: (direct)  (direct) - 1 Example: MOV 20H,A Example: DEC B ; B is at 0F0H Encoding: F5H 20H Encoding: 15H F0H Moving data MOV R5,A ; (R5)  (A) MOV A,R0 ; (A)  (R0) Logical operations ANL A,R5 ; (A)  (A) AND (R5) XRL R5,A ; (R5)  (R5) exOR (A) Arithmetic Operation ADD A,R3 ; (A)  (A) + (R3) ADDC A,R3 ; (A)  (A) + (R3) + C
  • 6. INSTRUCTION SET SUMMARY 8051 -6- Indirect Addressing The instruction specifies a register which contains the address of the operand. Opcode i Examples:- MOVX @Ri,A ADD A,@Ri Bytes: 1 Bytes: 1 Cycle: 2 Cycle: 1 Encoding: 1111001i Encoding: 0010011i Operation: ((Rn))  (A) Operation: (A)  (A) OR ((Ri)) Example: MOVX @R0,A Example: ADD A,@R1 Encoding: F2H Encoding: 27H Example:- MOV A,@R0 The Source is the memory location pointed by R0, the contents of which are copied into the Accumulator which is the destination register. MOV @R1,A The Accumulator is the source and its contents are copied into the destination which is the memory location pointed by R1. Example:- (a) What is the opcode for the following instruction? (b) What does this instruction do? MOV A,@R0
  • 7. INSTRUCTION SET SUMMARY 8051 -7- Solution (a) E6H (b) The instruction moves a byte of data from internal RAM to the Accumulator. The data are moved from the location whose address is in R0. Examples:- MOVX A,@DPTR MOVX @DPTR,A Bytes: 1 Bytes: 1 Cycle: 2 Cycle: 2 Encoding: 1110000 Encoding: 11110000 Operation: (A)  ((DPTR)) Operation: ((DPTR))  (A) Example:- Moving data MOV @R1,A ((R1))  (A) MOV A,@R1 (A)  ((R0)) Logical Operation ORL A,@R0 (A)  (A) OR ((R0)) XRL @R1,A ((R1))  ((R1)) exOR (A) Arithmetic Operation ADD A,@R0 (A)  (A) + ((R0)) ADDC A,@R1 (A)  (A) + ((R1)) + C Immediate Addressing The destination register is loaded with a constant value immediately. Opcode Immediate data
  • 8. INSTRUCTION SET SUMMARY 8051 -8- Examples:- ANL A,#data MOV DPTR,#DATA16 Bytes: 2 Bytes: 3 Cycle: 1 Cycle: 2 Encoding: 01010100 dddddddd Encoding: 10010000 dddddddd dddddddd Operation: (A)  (A) AND #data Operation: (DPTR)  #data16 Example: ANL A,#0F0H Example: MOV DPTR,#2800H Encoding: 54H F0H Encoding: 90H 28H 00H Example:- MOV A,#12 Loads the value of 12 into the Accumulator. Moving data MOV A,#F1H ; (A)  F1H MOV R3,#C1H ; (R3)  1CH Arithmetic Operation ADD A,#10H ; (A) (A) + 10H ADDC A,#10H ; (A) (A) + 10H + C Logical operation ORL A,#33H ; (A) (A) OR 33H ANL A,88H ; (15H)  (15H) AND 88H
  • 9. INSTRUCTION SET SUMMARY 8051 -9- Relative Addressing Relative Addressing is used only with certain jump instruction. A relative address or offset is an 8-bit signed value, which is added to the program counter to form the address of the next instruction executed. Range -128 to +127 locations. Opcode Relative Offset Example :- SJMP THERE THERE: MOV A,R1 ADD A,@R0 : : SJMP THERE 010A 0109 0108 0107 Relative offset from Address 0102H is “5” 0101 05 SJMP 0100 80 0107H 00FF Code Memory SJMP is in memory location 0100H and Offset is in the memory location 0101H. Destination = PC + offset = 0102 + 5
  • 10. INSTRUCTION SET SUMMARY 8051 -10- = 0107H Example:- The instruction SJMP 9030H is in the memory location 9000H and 9001H. What are the machine language bytes for this instruction? 80H, 2EH Destination = 9030H = PC + offset Therefore, offset = destination – PC = 9030H – 9002H = 2EH Example:- JZ rel JB bit,rel Bytes: 2 Bytes: 3 Cycle: 2 Cycle: 2 Encoding: 01100000 eeeeeeee Encoding: 00100000 bbbbbbbb eeeeeeee Operation: Operation: (PC)  (PC) + 2 (PC)  (PC) + 3 IF (A) = 0 IF (bit) = 1 Then (PC)  (PC) + byte_2 Then (PC)  (PC) + byte_3 Example:- LABEL: MOV A,P1 ANL A,#1 JZ LABEL MOV P0,P1 ……
  • 11. INSTRUCTION SET SUMMARY 8051 -11- Absolute Addressing This type of addressing mode is used only with ACALL and AJMP instruction. These 2-byte instructions allow branching within the current 2K page of code memory by providing the 11 least-significant bits of the destination address in the opcode (A10-A8) and byte 2 of the instruction (A7-A0). A10 – A8 Opcode A7 A6 A5 A4 A3 A2 A1 A0 2 K page 31 : : : 2 K page 2 2 K page 1 2 K page 0 FFFFH F800H Within any 2 K page only the lower 11 bits change OFFFH 0800H 07FFH 0000
  • 12. INSTRUCTION SET SUMMARY 8051 -12- Offers the advantage of short (2-byte) instructions, but has the disadvantages of limiting the range for the destination and providing position-dependent code. If the label THERE represents an instruction at address 0F46H, and the instruction AJMP THERE is in memory locations 0900H and 0901H, the assembler will encode the instruction as 111 00001 - 1st byte (A10 – A8 + opcode) 01000110 - 2nd byte (A7 – A0) 0F46H = 0000 1111 0100 1110B Example:- An ACALL instruction is in memory locations 1024H and 1025H. The subroutine to which the call is directed begins in memory location 17A6H. What are the machine language bytes for the ACALL instruction? Encoding for ACALL: aaa10001 aaaaaaaa A15A14A13A12 A11A10A9A8 A7A6A5A4 A3A2A1A0 17A6H = 0 0 0 1 0 1 1 1 1 0 1 0 0 1 1 0 Therefore, 11110001 10100110 = F1H, A6H
  • 13. INSTRUCTION SET SUMMARY 8051 -13- Long Addressing Long addressing is used only with the LCALL and LJMP instructions. These 3-byte instruction include a full 16-bit destination address as bytes 2 and 3 of the instruction. The 1st byte – Opcode 2nd and 3rd - Destination Address. Opcode A15–A8 High byte add. A7–A0 Low byte add. The advantage is that the full 64K code space may be used, but the disadvantage is that the instructions are 3 byte long and are position- dependent. Example:- LJMP addr16 LCALL addr16 Bytes: 3 Bytes: 3 Cycle: 2 Cycle: 2 Encoding: Encoding: 00000010 aaaaaaaa aaaaaaaa 00010010 aaaaaaaa aaaaaaaa Operation: Operation: (PC)  addr16 (PC)  (PC) + 3, (SP)  (SP) + 1, ((SP))  (PCL), (SP)  (SP) + 1, ((SP))  (PCH), (PC)  addr16 Example:- What are the machine language bytes for the following instruction? LJMP 8AF2H Opcode High Byte Add. Low Byte Add. Encoding :- 00000010 aaaaaaaa aaaaaaaa Hence, the machine language bytes are 02H, 8AH,F2H
  • 14. INSTRUCTION SET SUMMARY 8051 -14- Indexed Addressing Indexed Addressing uses a base register(either the PC or the data pointer) and an offset(Accumulator) in forming the effective address for a JMP or MOVC instruction. Opcode Jump tables or look-up tables are easily created using indexed addressing. Examples:- MOVC A,@A+<base-reg> and JMP @A+DPTR Example: What is the opcode for the following instruction? MOVC A,@A+DPTR Solution: 93 H Example:- REL_PC: INC A ;(A) <- (A) + 1 MOVC A,@A+PC RET DB 66H DB 77H DB 88H DB 99H If The subroutine is called with the accumulator equal to 01H, it returns with 77H in the accumulator. See Appendix C page 273 for further information.
  • 15. INSTRUCTION SET SUMMARY 8051 -15- Example:- Write a program to display 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 continuously through Port1. Insert some delay between each displayed digit. Display Common-Anode Display Common-Anode 0 C0H A 88H 1 F9H b 83H 2 A4H C C6H 3 B0H d A1H 4 99H E 86H 5 92H F 8EH 6 82H 7 F8H 8 80H 9 98H
  • 16. INSTRUCTION SET SUMMARY 8051 -16- ORG 0H ULANG: MOV P1,#0C0H LCALL DELAY MOV P1,#0F9H LCALL DELAY MOV P1,#0A4H LCALL DELAY - - - SJMP ULANG DELAY: MOV R5,#20H AGAIN: MOV R6,#255 LOOP1: MOV R7,#0F0H LOOP: DJNZ R7,LOOP DJNZ R6,LOOP1 DJNZ R5,AGAIN RET END OR
  • 17. INSTRUCTION SET SUMMARY 8051 -17- ORG 0000H ULANG: CLR A MOV R0,A MOV DPTR,#NOMBO TAMBAH: MOV A,R0 MOVC A,@A+DPTR MOV P1,A LCALL DELAY INC R0 CJNE R0,#11,TAMBAH SJMP ULANG DELAY: MOV R5,#10 LOOP2: MOV R6,#255 LOOP1: MOV R7,#255 LOOP: DJNZ R7,LOOP DJNZ R6,LOOP1 DJNZ R5,LOOP2 RET NOMBO: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,98H END