SlideShare une entreprise Scribd logo
1  sur  28
Microprocessors 1


                    The 8051 Instruction Set




Microprocessors 1           Msc. Ivan A. Escobar   1
                                  Broitman
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


Microprocessors 1         Msc. Ivan A. Escobar           2
                                Broitman
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.



Microprocessors 1             Msc. Ivan A. Escobar        3
                                    Broitman
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.




Microprocessors 1               Msc. Ivan A. Escobar                          4
                                      Broitman
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.

Microprocessors 1              Msc. Ivan A. Escobar              5
                                     Broitman
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




Microprocessors 1             Msc. Ivan A. Escobar          6
                                    Broitman
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.
Microprocessors 1             Msc. Ivan A. Escobar                7
                                    Broitman
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


Microprocessors 1                Msc. Ivan A. Escobar   8
                                       Broitman
Logical Operations
•   XRL
     – Works on bytes only.


•   CPL / CLR
     – Complement / Clear.
     – Work on the accumulator or a bit.
         • CLR P1.2




Microprocessors 1         Msc. Ivan A. Escobar   9
                                Broitman
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.

Microprocessors 1           Msc. Ivan A. Escobar        10
                                  Broitman
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



Microprocessors 1                 Msc. Ivan A. Escobar     11
                                        Broitman
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




Microprocessors 1         Msc. Ivan A. Escobar     12
                                Broitman
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




Microprocessors 1           Msc. Ivan A. Escobar               13
                                  Broitman
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




Microprocessors 1       Msc. Ivan A. Escobar          14
                              Broitman
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




Microprocessors 1           Msc. Ivan A. Escobar          15
                                  Broitman
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.


Microprocessors 1                Msc. Ivan A. Escobar                           16
                                       Broitman
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.

Microprocessors 1         Msc. Ivan A. Escobar       17
                                Broitman
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

Microprocessors 1             Msc. Ivan A. Escobar                    18
                                    Broitman
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.

Microprocessors 1         Msc. Ivan A. Escobar                      19
                                Broitman
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.


Microprocessors 1              Msc. Ivan A. Escobar            20
                                     Broitman
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.




Microprocessors 1                Msc. Ivan A. Escobar                         21
                                       Broitman
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


Microprocessors 1              Msc. Ivan A. Escobar                      22
                                     Broitman
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.

Microprocessors 1            Msc. Ivan A. Escobar            23
                                   Broitman
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.



Microprocessors 1             Msc. Ivan A. Escobar                       24
                                    Broitman
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.



Microprocessors 1              Msc. Ivan A. Escobar                          25
                                     Broitman
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.




Microprocessors 1              Msc. Ivan A. Escobar      26
                                     Broitman
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




Microprocessors 1             Msc. Ivan A. Escobar          27
                                    Broitman
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



Microprocessors 1             Msc. Ivan A. Escobar        28
                                    Broitman

Contenu connexe

Tendances

Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 completeShubham Singh
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controllerTech_MX
 
8257 DMA Controller
8257 DMA Controller8257 DMA Controller
8257 DMA ControllerShivamSood22
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051hello_priti
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerSudhanshu Janwadkar
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.pptDr.YNM
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor Mustapha Fatty
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architectureprasadpawaskar
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Urvashi Singh
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptxMemonaMemon1
 
8051 micro controllers Instruction set
8051 micro controllers Instruction set 8051 micro controllers Instruction set
8051 micro controllers Instruction set Nitin Ahire
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chipsSrikrishna Thota
 

Tendances (20)

8255 PPI
8255 PPI8255 PPI
8255 PPI
 
Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 complete
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
 
8257 DMA Controller
8257 DMA Controller8257 DMA Controller
8257 DMA Controller
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 Microcontroller
 
Shift Registers
Shift RegistersShift Registers
Shift Registers
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
8051 micro controllers Instruction set
8051 micro controllers Instruction set 8051 micro controllers Instruction set
8051 micro controllers Instruction set
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chips
 

Similaire à 8051 instruction set

8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdf8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdfMrRRThirrunavukkaras
 
Microcontroller architecture programming and interfacing
Microcontroller architecture programming and interfacingMicrocontroller architecture programming and interfacing
Microcontroller architecture programming and interfacingthejasmeetsingh
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction setprakash y
 
digital elctronics
digital elctronicsdigital elctronics
digital elctronicsAsif Iqbal
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontrollerSiva Kumar
 
8051 microcontroller notes continuous
8051 microcontroller notes continuous 8051 microcontroller notes continuous
8051 microcontroller notes continuous THANDAIAH PRABU
 
slides-main.pdf
slides-main.pdfslides-main.pdf
slides-main.pdfMatupi1
 
8086 microprocessor instruction set by Er. Swapnil Kaware
8086 microprocessor instruction set by Er. Swapnil Kaware8086 microprocessor instruction set by Er. Swapnil Kaware
8086 microprocessor instruction set by Er. Swapnil KawareProf. Swapnil V. Kaware
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communicationcanh phan
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarizeHisham Mat Hussin
 
MIPI DevCon 2016: Implementing MIPI C-PHY
MIPI DevCon 2016: Implementing MIPI C-PHYMIPI DevCon 2016: Implementing MIPI C-PHY
MIPI DevCon 2016: Implementing MIPI C-PHYMIPI Alliance
 
Microprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructionsMicroprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructionsArkhom Jodtang
 
8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).pptKanikaJindal9
 

Similaire à 8051 instruction set (20)

8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdf8051instructionset-120412233627-phpapp01.pdf
8051instructionset-120412233627-phpapp01.pdf
 
Uc 2(vii)
Uc 2(vii)Uc 2(vii)
Uc 2(vii)
 
Microcontroller architecture programming and interfacing
Microcontroller architecture programming and interfacingMicrocontroller architecture programming and interfacing
Microcontroller architecture programming and interfacing
 
13229286.ppt
13229286.ppt13229286.ppt
13229286.ppt
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
instructions set of 8051.pdf
instructions set of 8051.pdfinstructions set of 8051.pdf
instructions set of 8051.pdf
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
digital elctronics
digital elctronicsdigital elctronics
digital elctronics
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
 
module-3.pptx
module-3.pptxmodule-3.pptx
module-3.pptx
 
8051 microcontroller notes continuous
8051 microcontroller notes continuous 8051 microcontroller notes continuous
8051 microcontroller notes continuous
 
slides-main.pdf
slides-main.pdfslides-main.pdf
slides-main.pdf
 
8086 microprocessor instruction set by Er. Swapnil Kaware
8086 microprocessor instruction set by Er. Swapnil Kaware8086 microprocessor instruction set by Er. Swapnil Kaware
8086 microprocessor instruction set by Er. Swapnil Kaware
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communication
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarize
 
MIPI DevCon 2016: Implementing MIPI C-PHY
MIPI DevCon 2016: Implementing MIPI C-PHYMIPI DevCon 2016: Implementing MIPI C-PHY
MIPI DevCon 2016: Implementing MIPI C-PHY
 
Computer Networks
Computer NetworksComputer Networks
Computer Networks
 
Microprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructionsMicroprocessor Laboratory 2: Logical instructions
Microprocessor Laboratory 2: Logical instructions
 
8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt8085_Microprocessor(simar).ppt
8085_Microprocessor(simar).ppt
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
 

Dernier

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 

Dernier (20)

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 

8051 instruction set

  • 1. Microprocessors 1 The 8051 Instruction Set Microprocessors 1 Msc. Ivan A. Escobar 1 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 2 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 3 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 4 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 5 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 6 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 7 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 8 Broitman
  • 9. Logical Operations • XRL – Works on bytes only. • CPL / CLR – Complement / Clear. – Work on the accumulator or a bit. • CLR P1.2 Microprocessors 1 Msc. Ivan A. Escobar 9 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 10 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 11 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 12 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 13 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 14 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 15 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 16 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 17 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 18 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 19 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 20 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 21 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 22 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 23 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 24 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 25 Broitman
  • 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. Microprocessors 1 Msc. Ivan A. Escobar 26 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 27 Broitman
  • 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 Microprocessors 1 Msc. Ivan A. Escobar 28 Broitman