SlideShare a Scribd company logo
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 1
Microprocessors 1
The 8051 Instruction Set
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 2
Instruction Groups
• The 8051 has 255 instructions
– Every 8-bit opcode from 00 to FF is used except
for A5.
• The instructions are grouped into 5 groups
– Arithmetic
– Logic
– Data Transfer
– Boolean
– Branching
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 3
Arithmetic Instructions
• ADD
– 8-bit addition between the accumulator (A) and a
second operand.
• The result is always in the accumulator.
• The CY flag is set/reset appropriately.
• ADDC
– 8-bit addition between the accumulator, a second
operand and the previous value of the CY flag.
• Useful for 16-bit addition in two steps.
• The CY flag is set/reset appropriately.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 4
Example – 16-bit Addition
Add 1E44H to 56CAH
CLR C ; Clear the CY flag
MOV A, 44H ; The lower 8-bits of the 1st
number
ADD A, CAH ; The lower 8-bits of the 2nd
number
MOV R1, A ; The result 0EH will be in R1. CY = 1.
MOV A, 1EH ; The upper 8-bits of the 1st
number
ADDC A, 56H ; The upper 8-bits of the 2nd
number
MOV R2, A ; The result of the addition is 75H
The overall result: 750EH will be in R2:R1. CY = 0.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 5
Arithmetic Instructions
• DA
– Decimal adjust the accumulator.
• Format the accumulator into a proper 2 digit packed BCD
number.
• Operates only on the accumulator.
• Works only after the ADD instruction.
• SUBB
– Subtract with Borrow.
• Subtract an operand and the previous value of the
borrow (carry) flag from the accumulator.
– A ← A - <operand> - CY.
– The result is always saved in the accumulator.
– The CY flag is set/reset appropriately.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 6
Example – BCD addition
Add 34 to 49 BCD
CLR C ; Clear the CY flag
MOV A, #34H ; Place 1st
number in A
ADD A, #49H ; Add the 2nd
number.
; A = 7DH
DA A ; A = 83H
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 7
Arithmetic Instructions
• INC
– Increment the operand by one.
• The operand can be a register, a direct address, an
indirect address, the data pointer.
• DEC
– Decrement the operand by one.
• The operand can be a register, a direct address, an
indirect address.
• MUL AB / DIV AB
– Multiply A by B and place result in A:B.
– Divide A by B and place result in A:B.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 8
Logical Operations
• ANL / ORL
– Work on byte sized operands or the CY flag.
• ANL A, Rn
• ANL A, direct
• ANL A, @Ri
• ANL A, #data
• ANL direct, A
• ANL direct, #data
• ANL C, bit
• ANL C, /bit
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 9
Logical Operations
• XRL
– Works on bytes only.
• CPL / CLR
– Complement / Clear.
– Work on the accumulator or a bit.
• CLR P1.2
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 10
Logical Operations
• RL / RLC / RR / RRC
– Rotate the accumulator.
• RL and RR without the carry
• RLC and RRC rotate through the carry.
• SWAP A
– Swap the upper and lower nibbles of the
accumulator.
• No compare instruction.
– Built into conditional branching instructions.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 11
Data Transfer Instructions
• MOV
– 8-bit data transfer for internal RAM and the SFR.
• MOV A, Rn
• MOV A, direct
• MOV A, @Ri
• MOV A, #data
• MOV Rn, A
• MOV Rn, direct
• MOV Rn, #data
• MOV direct, A
• MOV direct, Rn
• MOV direct, direct
• MOV direct, @Ri
• MOV direct, #data
• MOV @Ri, A
• MOV @Ri, direct
• MOV @Ri, #data
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 12
Data Transfer Operations
• MOV
– 1-bit data transfer involving the CY flag
• MOV C, bit
• MOV bit, C
• MOV
– 16-bit data transfer involving the DPTR
• MOV DPTR, #data
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 13
Data Transfer Instructions
• MOVC
– Move Code Byte
• Load the accumulator with a byte from program memory.
• Must use indexed addressing
• MOVC A, @A+DPTR
• MOVC A, @A+PC
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 14
Data Transfer Instructions
• MOVX
– Data transfer between the accumulator and a byte
from external data memory.
• MOVX A, @Ri
• MOVX A, @DPTR
• MOVX @Ri, A
• MOVX @DPTR, A
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 15
Data Transfer Instructions
• PUSH / POP
– Push and Pop a data byte onto the stack.
– The data byte is identified by a direct address from
the internal RAM locations.
• PUSH DPL
• POP 40H
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 16
Data Transfer Instructions
• XCH
– Exchange accumulator and a byte variable
• XCH A, Rn
• XCH A, direct
• XCH A, @Ri
• XCHD
– Exchange lower digit of accumulator with the lower digit of
the memory location specified.
• XCHD A, @Ri
• The lower 4-bits of the accumulator are exchanged with the
lower 4-bits of the internal memory location identified indirectly
by the index register.
• The upper 4-bits of each are not modified.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 17
Boolean Operations
• This group of instructions is associated with the
single-bit operations of the 8051.
• This group allows manipulating the individual bits
of bit addressable registers and memory
locations as well as the CY flag.
– The P, OV, and AC flags cannot be directly
altered.
• This group includes:
– Set, clear, and, or complement, move.
– Conditional jumps.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 18
Boolean Operations
• CLR
– Clear a bit or the CY flag.
• CLR P1.1
• CLR C
• SETB
– Set a bit or the CY flag.
• SETB A.2
• SETB C
• CPL
– Complement a bit or the CY flag.
• CPL 40H ; Complement bit 40 of the bit
addressable memory
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 19
Boolean Operations
• ORL / ANL
– OR / AND a bit with the CY flag.
• ORL C, 20H ; OR bit 20 of bit addressable
memory with the CY flag
• ANL C, /34H ; AND complement of bit 34 of bit
addressable memory with the CY
flag.
• MOV
– Data transfer between a bit and the CY flag.
• MOV C, 3FH ; Copy the CY flag to bit 3F of the
bit addressable memory.
• MOV P1.2, C ; Copy the CY flag to bit 2 of P1.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 20
Boolean Operations
• JC / JNC
– Jump to a relative address if CY is set / cleared.
• JB / JNB
– Jump to a relative address if a bit is set / cleared.
• JB ACC.2, <label>
• JBC
– Jump to a relative address if a bit is set and clear
the bit.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 21
Branching Instructions
• The 8051 provides four different types of
unconditional jump instructions:
– Short Jump – SJMP
• Uses an 8-bit signed offset relative to the 1st
byte of the next
instruction.
– Long Jump – LJMP
• Uses a 16-bit address.
• 3 byte instruction capable of referencing any location in the
entire 64K of program memory.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 22
Branching Instructions
– Absolute Jump – AJMP
• Uses an 11-bit address.
• 2 byte instruction
– The upper 3-bits of the address combine with the 5-bit
opcode to form the 1st
byte and the lower 8-bits of the
address form the 2nd
byte.
• The 11-bit address is substituted for the lower 11-bits of
the PC to calculate the 16-bit address of the target.
– The location referenced must be within the 2K Byte
memory page containing the AJMP instruction.
– Indirect Jump – JMP
• JMP @A + DPTR
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 23
Branching Instructions
• The 8051 provides 2 forms for the CALL
instruction:
– Absolute Call – ACALL
• Uses an 11-bit address similar to AJMP
• The subroutine must be within the same 2K page.
– Long Call – LCALL
• Uses a 16-bit address similar to LJMP
• The subroutine can be anywhere.
– Both forms push the 16-bit address of the next
instruction on the stack and update the stack
pointer.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 24
Branching Instructions
• The 8051 provides 2 forms for the return
instruction:
– Return from subroutine – RET
• Pop the return address from the stack and continue
execution there.
– Return from ISV – RETI
• Pop the return address from the stack.
• Restore the interrupt logic to accept additional interrupts
at the same priority level as the one just processed.
• Continue execution at the address retrieved from the
stack.
• The PSW is not automatically restored.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 25
Branching Instructions
• The 8051 supports 5 different conditional jump
instructions.
– ALL conditional jump instructions use an 8-bit
signed offset.
– Jump on Zero – JZ / JNZ
• Jump if the A == 0 / A != 0
– The check is done at the time of the instruction execution.
– Jump on Carry – JC / JNC
• Jump if the C flag is set / cleared.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 26
Branching Instructions
– Jump on Bit – JB / JNB
• Jump if the specified bit is set / cleared.
• Any addressable bit can be specified.
– Jump if the Bit is set then Clear the bit – JBC
• Jump if the specified bit is set.
• Then clear the bit.
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 27
Branching Instructions
• Compare and Jump if Not Equal – CJNE
– Compare the magnitude of the two operands and
jump if they are not equal.
• The values are considered to be unsigned.
• The Carry flag is set / cleared appropriately.
• CJNE A, direct, rel
• CJNE A, #data, rel
• CJNE Rn, #data, rel
• CJNE @Ri, #data, rel
Msc. Ivan A. Escobar
Broitman
Microprocessors 1 28
Branching Instructions
• Decrement and Jump if Not Zero – DJNZ
– Decrement the first operand by 1 and jump to the
location identified by the second operand if the
resulting value is not zero.
• DJNZ Rn, rel
• DJNZ direct, rel
• No Operation
– NOP

More Related Content

Similar to 8051instructionset-120412233627-phpapp01.pdf

digital elctronics
digital elctronicsdigital elctronics
digital elctronics
Asif Iqbal
 
5th unit Microprocessor 8085
5th unit Microprocessor 80855th unit Microprocessor 8085
5th unit Microprocessor 8085
Mani Afranzio
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
karthiga selvaraju
 
Chapter 6 - Introduction to 8085 Instructions
Chapter 6 - Introduction to 8085 InstructionsChapter 6 - Introduction to 8085 Instructions
Chapter 6 - Introduction to 8085 Instructions
cmkandemir
 
Lect08
Lect08Lect08
Digital logic and microprocessors
Digital logic and microprocessorsDigital logic and microprocessors
Digital logic and microprocessors
Milind Pelagade
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communicationcanh phan
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
MalligaarjunanN
 
module-2.pptx
module-2.pptxmodule-2.pptx
module-2.pptx
Ambika Naik
 
Pic18 f4520 and robotics
Pic18 f4520 and roboticsPic18 f4520 and robotics
Pic18 f4520 and roboticsSiddhant Chopra
 
Plc
PlcPlc
Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)Pratheesh Pala
 
8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt
KanikaJindal9
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
Siva Kumar
 
unit5_8051_microcontroller presentation.pdf
unit5_8051_microcontroller presentation.pdfunit5_8051_microcontroller presentation.pdf
unit5_8051_microcontroller presentation.pdf
tchandoo1
 
Microprocessors-based systems (under graduate course) Lecture 4 of 9
Microprocessors-based systems (under graduate course) Lecture 4 of 9 Microprocessors-based systems (under graduate course) Lecture 4 of 9
Microprocessors-based systems (under graduate course) Lecture 4 of 9
Randa Elanwar
 
Microcontroller architecture programming and interfacing
Microcontroller architecture programming and interfacingMicrocontroller architecture programming and interfacing
Microcontroller architecture programming and interfacing
thejasmeetsingh
 
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERSPIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
VISHNU KP
 
arithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxarithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptx
AshokRachapalli1
 

Similar to 8051instructionset-120412233627-phpapp01.pdf (20)

digital elctronics
digital elctronicsdigital elctronics
digital elctronics
 
5th unit Microprocessor 8085
5th unit Microprocessor 80855th unit Microprocessor 8085
5th unit Microprocessor 8085
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Chapter 6 - Introduction to 8085 Instructions
Chapter 6 - Introduction to 8085 InstructionsChapter 6 - Introduction to 8085 Instructions
Chapter 6 - Introduction to 8085 Instructions
 
Lect08
Lect08Lect08
Lect08
 
Digital logic and microprocessors
Digital logic and microprocessorsDigital logic and microprocessors
Digital logic and microprocessors
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communication
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
 
module-2.pptx
module-2.pptxmodule-2.pptx
module-2.pptx
 
Pic18 f4520 and robotics
Pic18 f4520 and roboticsPic18 f4520 and robotics
Pic18 f4520 and robotics
 
Plc
PlcPlc
Plc
 
Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)
 
8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
 
unit5_8051_microcontroller presentation.pdf
unit5_8051_microcontroller presentation.pdfunit5_8051_microcontroller presentation.pdf
unit5_8051_microcontroller presentation.pdf
 
Microprocessors-based systems (under graduate course) Lecture 4 of 9
Microprocessors-based systems (under graduate course) Lecture 4 of 9 Microprocessors-based systems (under graduate course) Lecture 4 of 9
Microprocessors-based systems (under graduate course) Lecture 4 of 9
 
Microcontroller architecture programming and interfacing
Microcontroller architecture programming and interfacingMicrocontroller architecture programming and interfacing
Microcontroller architecture programming and interfacing
 
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERSPIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
PIC-MICROCONTROLLER TUTORIALS FOR BEGINNERS
 
arithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxarithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptx
 
Co ppt
Co pptCo ppt
Co ppt
 

More from MrRRThirrunavukkaras

VLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptx
VLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptxVLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptx
VLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptx
MrRRThirrunavukkaras
 
Combinational Circuits Design in Digital System Design.pptx
Combinational Circuits Design in Digital System Design.pptxCombinational Circuits Design in Digital System Design.pptx
Combinational Circuits Design in Digital System Design.pptx
MrRRThirrunavukkaras
 
Electronics for basic engineers and .ppt
Electronics for basic engineers and .pptElectronics for basic engineers and .ppt
Electronics for basic engineers and .ppt
MrRRThirrunavukkaras
 
Verilog Hardware Description Language.ppt
Verilog Hardware Description Language.pptVerilog Hardware Description Language.ppt
Verilog Hardware Description Language.ppt
MrRRThirrunavukkaras
 
Search-Beyond-Classical-no-exercise-answers.pdf
Search-Beyond-Classical-no-exercise-answers.pdfSearch-Beyond-Classical-no-exercise-answers.pdf
Search-Beyond-Classical-no-exercise-answers.pdf
MrRRThirrunavukkaras
 
Adaptive Cruise Control.pdf
Adaptive Cruise Control.pdfAdaptive Cruise Control.pdf
Adaptive Cruise Control.pdf
MrRRThirrunavukkaras
 
certificate wordings.docx
certificate wordings.docxcertificate wordings.docx
certificate wordings.docx
MrRRThirrunavukkaras
 
wearable_HAPTIC_TECHNOLOGY_pptx.pptx
wearable_HAPTIC_TECHNOLOGY_pptx.pptxwearable_HAPTIC_TECHNOLOGY_pptx.pptx
wearable_HAPTIC_TECHNOLOGY_pptx.pptx
MrRRThirrunavukkaras
 

More from MrRRThirrunavukkaras (8)

VLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptx
VLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptxVLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptx
VLSI DESIGN BASICS TRANSISTOR THEORY AND MOS TRANSISTOR.pptx
 
Combinational Circuits Design in Digital System Design.pptx
Combinational Circuits Design in Digital System Design.pptxCombinational Circuits Design in Digital System Design.pptx
Combinational Circuits Design in Digital System Design.pptx
 
Electronics for basic engineers and .ppt
Electronics for basic engineers and .pptElectronics for basic engineers and .ppt
Electronics for basic engineers and .ppt
 
Verilog Hardware Description Language.ppt
Verilog Hardware Description Language.pptVerilog Hardware Description Language.ppt
Verilog Hardware Description Language.ppt
 
Search-Beyond-Classical-no-exercise-answers.pdf
Search-Beyond-Classical-no-exercise-answers.pdfSearch-Beyond-Classical-no-exercise-answers.pdf
Search-Beyond-Classical-no-exercise-answers.pdf
 
Adaptive Cruise Control.pdf
Adaptive Cruise Control.pdfAdaptive Cruise Control.pdf
Adaptive Cruise Control.pdf
 
certificate wordings.docx
certificate wordings.docxcertificate wordings.docx
certificate wordings.docx
 
wearable_HAPTIC_TECHNOLOGY_pptx.pptx
wearable_HAPTIC_TECHNOLOGY_pptx.pptxwearable_HAPTIC_TECHNOLOGY_pptx.pptx
wearable_HAPTIC_TECHNOLOGY_pptx.pptx
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

8051instructionset-120412233627-phpapp01.pdf

  • 1. Msc. Ivan A. Escobar Broitman Microprocessors 1 1 Microprocessors 1 The 8051 Instruction Set
  • 2. Msc. Ivan A. Escobar Broitman Microprocessors 1 2 Instruction Groups • The 8051 has 255 instructions – Every 8-bit opcode from 00 to FF is used except for A5. • The instructions are grouped into 5 groups – Arithmetic – Logic – Data Transfer – Boolean – Branching
  • 3. Msc. Ivan A. Escobar Broitman Microprocessors 1 3 Arithmetic Instructions • ADD – 8-bit addition between the accumulator (A) and a second operand. • The result is always in the accumulator. • The CY flag is set/reset appropriately. • ADDC – 8-bit addition between the accumulator, a second operand and the previous value of the CY flag. • Useful for 16-bit addition in two steps. • The CY flag is set/reset appropriately.
  • 4. Msc. Ivan A. Escobar Broitman Microprocessors 1 4 Example – 16-bit Addition Add 1E44H to 56CAH CLR C ; Clear the CY flag MOV A, 44H ; The lower 8-bits of the 1st number ADD A, CAH ; The lower 8-bits of the 2nd number MOV R1, A ; The result 0EH will be in R1. CY = 1. MOV A, 1EH ; The upper 8-bits of the 1st number ADDC A, 56H ; The upper 8-bits of the 2nd number MOV R2, A ; The result of the addition is 75H The overall result: 750EH will be in R2:R1. CY = 0.
  • 5. Msc. Ivan A. Escobar Broitman Microprocessors 1 5 Arithmetic Instructions • DA – Decimal adjust the accumulator. • Format the accumulator into a proper 2 digit packed BCD number. • Operates only on the accumulator. • Works only after the ADD instruction. • SUBB – Subtract with Borrow. • Subtract an operand and the previous value of the borrow (carry) flag from the accumulator. – A ← A - <operand> - CY. – The result is always saved in the accumulator. – The CY flag is set/reset appropriately.
  • 6. Msc. Ivan A. Escobar Broitman Microprocessors 1 6 Example – BCD addition Add 34 to 49 BCD CLR C ; Clear the CY flag MOV A, #34H ; Place 1st number in A ADD A, #49H ; Add the 2nd number. ; A = 7DH DA A ; A = 83H
  • 7. Msc. Ivan A. Escobar Broitman Microprocessors 1 7 Arithmetic Instructions • INC – Increment the operand by one. • The operand can be a register, a direct address, an indirect address, the data pointer. • DEC – Decrement the operand by one. • The operand can be a register, a direct address, an indirect address. • MUL AB / DIV AB – Multiply A by B and place result in A:B. – Divide A by B and place result in A:B.
  • 8. Msc. Ivan A. Escobar Broitman Microprocessors 1 8 Logical Operations • ANL / ORL – Work on byte sized operands or the CY flag. • ANL A, Rn • ANL A, direct • ANL A, @Ri • ANL A, #data • ANL direct, A • ANL direct, #data • ANL C, bit • ANL C, /bit
  • 9. Msc. Ivan A. Escobar Broitman Microprocessors 1 9 Logical Operations • XRL – Works on bytes only. • CPL / CLR – Complement / Clear. – Work on the accumulator or a bit. • CLR P1.2
  • 10. Msc. Ivan A. Escobar Broitman Microprocessors 1 10 Logical Operations • RL / RLC / RR / RRC – Rotate the accumulator. • RL and RR without the carry • RLC and RRC rotate through the carry. • SWAP A – Swap the upper and lower nibbles of the accumulator. • No compare instruction. – Built into conditional branching instructions.
  • 11. Msc. Ivan A. Escobar Broitman Microprocessors 1 11 Data Transfer Instructions • MOV – 8-bit data transfer for internal RAM and the SFR. • MOV A, Rn • MOV A, direct • MOV A, @Ri • MOV A, #data • MOV Rn, A • MOV Rn, direct • MOV Rn, #data • MOV direct, A • MOV direct, Rn • MOV direct, direct • MOV direct, @Ri • MOV direct, #data • MOV @Ri, A • MOV @Ri, direct • MOV @Ri, #data
  • 12. Msc. Ivan A. Escobar Broitman Microprocessors 1 12 Data Transfer Operations • MOV – 1-bit data transfer involving the CY flag • MOV C, bit • MOV bit, C • MOV – 16-bit data transfer involving the DPTR • MOV DPTR, #data
  • 13. Msc. Ivan A. Escobar Broitman Microprocessors 1 13 Data Transfer Instructions • MOVC – Move Code Byte • Load the accumulator with a byte from program memory. • Must use indexed addressing • MOVC A, @A+DPTR • MOVC A, @A+PC
  • 14. Msc. Ivan A. Escobar Broitman Microprocessors 1 14 Data Transfer Instructions • MOVX – Data transfer between the accumulator and a byte from external data memory. • MOVX A, @Ri • MOVX A, @DPTR • MOVX @Ri, A • MOVX @DPTR, A
  • 15. Msc. Ivan A. Escobar Broitman Microprocessors 1 15 Data Transfer Instructions • PUSH / POP – Push and Pop a data byte onto the stack. – The data byte is identified by a direct address from the internal RAM locations. • PUSH DPL • POP 40H
  • 16. Msc. Ivan A. Escobar Broitman Microprocessors 1 16 Data Transfer Instructions • XCH – Exchange accumulator and a byte variable • XCH A, Rn • XCH A, direct • XCH A, @Ri • XCHD – Exchange lower digit of accumulator with the lower digit of the memory location specified. • XCHD A, @Ri • The lower 4-bits of the accumulator are exchanged with the lower 4-bits of the internal memory location identified indirectly by the index register. • The upper 4-bits of each are not modified.
  • 17. Msc. Ivan A. Escobar Broitman Microprocessors 1 17 Boolean Operations • This group of instructions is associated with the single-bit operations of the 8051. • This group allows manipulating the individual bits of bit addressable registers and memory locations as well as the CY flag. – The P, OV, and AC flags cannot be directly altered. • This group includes: – Set, clear, and, or complement, move. – Conditional jumps.
  • 18. Msc. Ivan A. Escobar Broitman Microprocessors 1 18 Boolean Operations • CLR – Clear a bit or the CY flag. • CLR P1.1 • CLR C • SETB – Set a bit or the CY flag. • SETB A.2 • SETB C • CPL – Complement a bit or the CY flag. • CPL 40H ; Complement bit 40 of the bit addressable memory
  • 19. Msc. Ivan A. Escobar Broitman Microprocessors 1 19 Boolean Operations • ORL / ANL – OR / AND a bit with the CY flag. • ORL C, 20H ; OR bit 20 of bit addressable memory with the CY flag • ANL C, /34H ; AND complement of bit 34 of bit addressable memory with the CY flag. • MOV – Data transfer between a bit and the CY flag. • MOV C, 3FH ; Copy the CY flag to bit 3F of the bit addressable memory. • MOV P1.2, C ; Copy the CY flag to bit 2 of P1.
  • 20. Msc. Ivan A. Escobar Broitman Microprocessors 1 20 Boolean Operations • JC / JNC – Jump to a relative address if CY is set / cleared. • JB / JNB – Jump to a relative address if a bit is set / cleared. • JB ACC.2, <label> • JBC – Jump to a relative address if a bit is set and clear the bit.
  • 21. Msc. Ivan A. Escobar Broitman Microprocessors 1 21 Branching Instructions • The 8051 provides four different types of unconditional jump instructions: – Short Jump – SJMP • Uses an 8-bit signed offset relative to the 1st byte of the next instruction. – Long Jump – LJMP • Uses a 16-bit address. • 3 byte instruction capable of referencing any location in the entire 64K of program memory.
  • 22. Msc. Ivan A. Escobar Broitman Microprocessors 1 22 Branching Instructions – Absolute Jump – AJMP • Uses an 11-bit address. • 2 byte instruction – The upper 3-bits of the address combine with the 5-bit opcode to form the 1st byte and the lower 8-bits of the address form the 2nd byte. • The 11-bit address is substituted for the lower 11-bits of the PC to calculate the 16-bit address of the target. – The location referenced must be within the 2K Byte memory page containing the AJMP instruction. – Indirect Jump – JMP • JMP @A + DPTR
  • 23. Msc. Ivan A. Escobar Broitman Microprocessors 1 23 Branching Instructions • The 8051 provides 2 forms for the CALL instruction: – Absolute Call – ACALL • Uses an 11-bit address similar to AJMP • The subroutine must be within the same 2K page. – Long Call – LCALL • Uses a 16-bit address similar to LJMP • The subroutine can be anywhere. – Both forms push the 16-bit address of the next instruction on the stack and update the stack pointer.
  • 24. Msc. Ivan A. Escobar Broitman Microprocessors 1 24 Branching Instructions • The 8051 provides 2 forms for the return instruction: – Return from subroutine – RET • Pop the return address from the stack and continue execution there. – Return from ISV – RETI • Pop the return address from the stack. • Restore the interrupt logic to accept additional interrupts at the same priority level as the one just processed. • Continue execution at the address retrieved from the stack. • The PSW is not automatically restored.
  • 25. Msc. Ivan A. Escobar Broitman Microprocessors 1 25 Branching Instructions • The 8051 supports 5 different conditional jump instructions. – ALL conditional jump instructions use an 8-bit signed offset. – Jump on Zero – JZ / JNZ • Jump if the A == 0 / A != 0 – The check is done at the time of the instruction execution. – Jump on Carry – JC / JNC • Jump if the C flag is set / cleared.
  • 26. Msc. Ivan A. Escobar Broitman Microprocessors 1 26 Branching Instructions – Jump on Bit – JB / JNB • Jump if the specified bit is set / cleared. • Any addressable bit can be specified. – Jump if the Bit is set then Clear the bit – JBC • Jump if the specified bit is set. • Then clear the bit.
  • 27. Msc. Ivan A. Escobar Broitman Microprocessors 1 27 Branching Instructions • Compare and Jump if Not Equal – CJNE – Compare the magnitude of the two operands and jump if they are not equal. • The values are considered to be unsigned. • The Carry flag is set / cleared appropriately. • CJNE A, direct, rel • CJNE A, #data, rel • CJNE Rn, #data, rel • CJNE @Ri, #data, rel
  • 28. Msc. Ivan A. Escobar Broitman Microprocessors 1 28 Branching Instructions • Decrement and Jump if Not Zero – DJNZ – Decrement the first operand by 1 and jump to the location identified by the second operand if the resulting value is not zero. • DJNZ Rn, rel • DJNZ direct, rel • No Operation – NOP