8051 Instruction Set PDF
Document Details
Uploaded by AffableLime
null
Tags
Summary
This document provides an overview of the 8051 microcontroller instruction set. It details various instruction categories, including arithmetic, logical, program branching, and data transfer instructions. The document also includes examples, mnemonics, and the flags affected by different instructions.
Full Transcript
1 ❑ All microcontrollers compatible with the 8051 have in total of 255 instructions, i.e. 255 different words available for program writing. ❑ Many instructions are considered to be “different”, even though they perform the same operation, so there are only 111 truly different...
1 ❑ All microcontrollers compatible with the 8051 have in total of 255 instructions, i.e. 255 different words available for program writing. ❑ Many instructions are considered to be “different”, even though they perform the same operation, so there are only 111 truly different commands. ❑ For example: ADD A,R0, ADD A,R1,... ADD A,R7 are instructions that perform the same operation (addition of the accumulator and register). Taking into account that all instructions perform only 53 operations (addition, subtraction, copy etc.) MODULE - 3 ECE3003 – Microcontroller and its Applications 3 ❑ 8051 instructions have 8-bit opcode There are 256 possible instructions of which 255 are implemented Every 8-bit opcode from 00 to FF is used except for A5. Some instructions have one or two additional bytes for data or address There are 139 1-byte instructions, 92 2-byte instructions, and 24 3-byte instruction MODULE - 3 ECE3003 – Microcontroller and its Applications 4 ❑ Depending on operation they perform, all instructions are divided in 5 groups: 1. Arithmetic Instructions 2. Logic Instructions 3. Program Branching Instructions 4. Boolean or Bit-oriented Instructions 5. Data Transfer Instructions MODULE - 3 ECE3003 – Microcontroller and its Applications 5 DATA TRANSFER ARITHMETIC LOGICAL BOOLEAN PROGRAM BRANCHING MOV ADD / ADDC ANL CLR JMP / SJMP / AJMP/ LJMP MOVC SUBB ORL SETB LCALL / ACALL MOVX INC XRL MOV RET / RETI PUSH DEC ANL JZ / JNZ POP MUL ORL JC /JNC XCH DIV CPL JB / JNB XCHD DA A JBC CLR CJNE CPL DJNZ RL / RLC NOP RR / RRC SWAP MODULE - 3 ECE3003 – Microcontroller and its Applications 6 ARITHMETIC INSTRUCTIONS ❑ Using Arithmetic Instructions, you can perform addition, subtraction, multiplication and division. ❑ The arithmetic instructions also include increment by one, decrement by one and Decimal Adjust Accumulator. ❑ The arithmetic instructions has no knowledge about the data format i.e. signed, unsigned, ASCII, BCD, etc. ❑ The operations performed by the arithmetic instructions affect flags like carry, overflow, zero, etc. in the PSW MODULE - 3 ECE3003 – Microcontroller and its Applications 7 ARITHMETIC INSTRUCTIONS ❑ The Mnemonics associated with the Arithmetic Instructions of the 8051 Microcontroller Instruction Set are: ADD CLR ADDC CPL SUBB RL MUL RLC DIV INC RR DEC RRC DA A SWAP MODULE - 3 ECE3003 – Microcontroller and its Applications 8 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 9 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 10 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 11 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 12 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 13 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 14 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 15 ARITHMETIC INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 16 LOGICAL INSTRUCTIONS ❑ The Logical Instructions perform logical operations like AND, OR, XOR. ❑ Logical Instruction are performed on Bytes of data on a bit- by-bit basis. ANL ORL XRL MODULE - 3 ECE3003 – Microcontroller and its Applications 17 LOGICAL INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 18 LOGICAL INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 19 BOOLEAN OR BIT-ORIENTED INSTRUCTIONS ❑ The Boolean or Bit Manipulation Instructions will deal with bit variables. ❑ We know that there is a special bit-addressable area in the RAM and some of the Special Function Registers (SFRs) are also bit addressable. CLR SETB CPL MOV ANL ORL MODULE - 3 ECE3003 – Microcontroller and its Applications 20 BOOLEAN OR BIT-ORIENTED INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 21 BOOLEAN OR BIT-ORIENTED INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 22 BOOLEAN OR BIT-ORIENTED INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 23 PROGRAM BRANCHING INSTRUCTIONS ❑ These instructions control the flow of program logic. SJMP JZ / JNZ LJMP JC / JNC AJMP JB / JNB JMP JBC LCALL CJNE ACALL DJNZ RET NOP RETI MODULE - 3 ECE3003 – Microcontroller and its Applications 24 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 25 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 26 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 27 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 28 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 29 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 30 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 32 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 33 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 34 PROGRAM BRANCHING INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 35 DATA TRANSFER INSTRUCTIONS ❑ The Data Transfer Instructions are associated with transfer with data between registers or external program memory or external data memory. MOV MOVC MOVX PUSH POP XCH XCHD MODULE - 3 ECE3003 – Microcontroller and its Applications 36 DATA TRANSFER INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 37 DATA TRANSFER INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 38 DATA TRANSFER INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 39 DATA TRANSFER INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 40 DATA TRANSFER INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 41 DATA TRANSFER INSTRUCTIONS MODULE - 3 ECE3003 – Microcontroller and its Applications 42 43 Flag: It is a 1-bit register that indicates the status of the result from an operation Flags are either at a flag-state of value 0 or 1 Arithmetic flags indicate the status of the results from mathematical operations (+, −, *, /) There are 4 arithmetic flags in the 8051:Carry (C), Auxiliary Carry (AC), Overflow (OV), Parity (P) All the above flags are stored in the Program Status Word(PSW) MODULE - 3 ECE3003 – Microcontroller and its Applications 44 INSTRUCTIONS THAT AFFECTING FLAGS MODULE - 3 ECE3003 – Microcontroller and its Applications 45 INSTRUCTIONS THAT AFFECTING FLAGS MODULE - 3 ECE3003 – Microcontroller and its Applications 46 EXAMPLE Show how the flag register is affected by the following instructions. MOV A, #0F5h ; A = F5h ADD A, #0Bh ; A = F5 + 0B = 00 Solution F5h 1111 0101 + 0Bh + 0000 1011 100h 0000 0000 After the addition, register A (destination) contains 00 and the flags are: CY = 1 since there is a carry out from D7 P = 0 because the number of 1s is zero AC = 1 since there is a carry from D3 to D4 MODULE - 3 ECE3003 – Microcontroller and its Applications 47 48 ❑ Addressing mode is a way to address an operand. Operand means the data we are operating upon. ❑ There are eight addressing modes available in the 8051: – Immediate – Direct – Register - Register indirect – Indexed MODULE - 3 ECE3003 – Microcontroller and its Applications 49 IMMEDIATE ADDRESSING MODE ❑ This addressing mode is named as “immediate” because it transfers an 8-bit data immediately to the accumulator (destination operand). ❑ In general we can write MOV A, #data. MOV A, #6AH ❑ The ‘#’ symbol before 6AH indicates that operand is a data (8 bit). If ‘#’ is not present then the hexadecimal number would be taken as address. MODULE - 3 ECE3003 – Microcontroller and its Applications 50 DIRECT ADDRESSING MODE ❑ Here the address of the data (source data ) is given as operand. Lets take an example. MOV A, 04H ❑ Here 04H is the address of register 4 of register bank#0. When this instruction is executed, what ever data is stored in register 04H is moved to accumulator. ❑ In the figure register 04H holds the data 1FH. So the data 1FH is moved to accumulator. MODULE - 3 ECE3003 – Microcontroller and its Applications 53 REGISTER ADDRESSING MODE ❑ In this addressing mode we use the register name directly (as source operand). At a time registers can take value from R0,R1…to R7.An example is shown below. MOV A, R4 ❑ In register direct addressing mode, data is transferred to accumulator from the register (based on which register bank is selected). ❑ PSW.3 and PSW.4bits are known as register bank select bits as they are used to select register banks. MODULE - 3 ECE3003 – Microcontroller and its Applications 56 REGISTER INDIRECT ADDRESSING MODE ❑ In this addressing mode, address of the data (source data to transfer) is given in the register operand. MOV A, @R0 ❑ Here the value inside R0 is considered as an address, which holds the data to be transferred to accumulator ❑ If R0 holds the value 20H, and we have a data 2F H stored at the address 20H, then the value 2FH will get transferred to accumulator after executing this instruction. MODULE - 3 ECE3003 – Microcontroller and its Applications 59 INDEXED ADDRESSING MODE MOVC A, @A+DPTR and MOVC A, @A+PC ❑ where DPTR is data pointer and PC is program counter (both are 16 bit registers). ❑ The source operand is @A+DPTR and we will get the source data (to transfer) from this location. ❑ It is nothing but adding contents of DPTR with present content of accumulator. This addition will result a new data which is taken as the address of source data (to transfer). The data at this address is then transferred to accumulator. MODULE - 3 ECE3003 – Microcontroller and its Applications 62