INSTRUCTION SET 

  • The instructions are classified according to the type of operation performed by them. All instructions can be divided into four categories. 

1. Data movement instructions 

2. Arithmetic instructions 

3. Logical instructions 

4. Program flow control instructions


ADDRESSING MODES 

  • The way by which source or destination (usually source) operands are specified in instructions 
  • There are essentially four addressing modes used by all microcontrollers are called addressing mode. They are, 

1. Immediate addressing 

2. Register addressing 

3. Direct addressing 

4. Indirect addressing






The memory of the 8051 may be divided in five types of address spaces. The operands are located in any of the address spaces. The five address spaces are, 

1. Bank registers (R0-R7) 
2. Accumulator
3. Internal data RAM (00-7F & SFRs) 
4. External data RAM (data memory) 
5. Program ROM (internal + external ROM)


Immediate addressing mode

 The data is available immediately as a part of the instruction itself. 

MOV A, #data // load 8 bit immediate data in to Accumulator 
MOV A, #55H // A= 55H 

MOV Rn, #data// load 8 bit immediate data into Rn 
MOV R3, #0FFH // R3= FFH 

MOV DPTR, #data16 // load 16-bit number into DPTR 
MOV DPTR, #2000H // DPTR=2000H





Notations for numbers of different number systems






Register addressing mode 


In register addressing mode, the operands are specified by register names. Register A and R0 to R7 may be named as a part of the instruction mnemonic. 

MOV A, Rn // copy contents of register Rn to Accumulator 
MOV A, R2 // If R2=10H →A=10H 

MOV Rn, A // copy contents of Accumulator to register Rn 
MOV R1, A // If A=20H →R1=20H



Direct addressing mode 

The data is accessed directly from the memory address specified as one of the operand i.e. one of the operands is an 8-bit address for internal RAM location. 

MOV A, direct // copy data from (contents of) address direct in to A 
MOV A, 10H // If address 10H contains data 50H i.e (10H)=50H→ // A=50H 

MOV direct, A // copy data from A to address direct 
MOV 10H, A // If A=44H→ (10H)= 44H 

MOV Rn, direct // copy data from address direct in to register Rn 
MOV R5, 80H // If (80H)= FFH→ R5= FFH 

MOV direct, Rn // copy data from Rn to address direct 
MOV 50H, R3 // R3=10H →(50H)= 10H

MOV direct, #data // load 8 bit immediate data in to address direct 
MOV 0A0H, #20H // (A0H) = 20H 

MOV direct1, direct2 // copy data from address direct2 to address direct1 
MOV 50H, 83H // If (83H)=10H→ (50H)=10H





Indirect addressing mode 


The data is specified indirectly in an instruction i.e. address of the data (rather than data itself) is specified as one of the operand. 

  • Register indirect addressing mode 

MOV @Ri, #data // load constant value in to address contained // in Ri 
MOV @R0, #30H // If R0=40H, → (40H)=30H 

MOV @Ri, direct // copy data form address direct to address Ri 
MOV @R1, 10H // If (10H)=50H, R1=15H→ (15H)=50H 

MOV direct, @Ri // copy data from address in Ri to address direct 
MOV 10H, @R1 // If R1=50H, (50H)=15H→ (10H)=15H 

MOV @Ri, A // copy data from A to address in Ri 
MOV @R0, A // If A=50H, R0=15H→ (15H)=50H 

MOV A, @Ri // copy data from address in Ri to A 
MOV A, @R1 // If R1=50H, (50H)=15H→ A=15H I

ndirect addressing can access internal as well as external memory area. The indirect addresses can be 8 bits or 16 bits. The 8 bit addresses as mentioned above are held by R0, R1 or SP only. The 16 bit addresses are held by DPTR, for external memory.






Indexed addressing mode 

MOVC A, @A+PC // copy data (or code) byte from program 
                                // memory address formed by 
                               //addition of contents of A and PC into A 
MOVC A, @A+DPTR    // copy data (or code) byte from program 
                                        // memory address formed by 
                                       // addition of contents of A and DPTR into A



OPERAND MODIFIERS: # AND @ 


The symbol # written before operand indicates it is an immediate operand while the symbol @ placed before an operand indicates that indirect addressing mode is used. 

MOV A, #50H // 50H is immediate operand 
MOV A, 50H // 50H is direct operand 
MOV A, R1 // R1 is register operand 
MOV A, @R1 // R1 is indirect register operand







EXTERNAL MEMORY DATA MOVEMENTS 


The external memory in the 8051 based system may be either data memory (RAM) or program memory (ROM). Instructions that access external memory always use indirect addressing mode. Two different set of instructions are used to transfer data to/from data memory and from program memory. 

1. Data memory access 
2. Program memory access 


Data memory access 


The data memory can be as large as 64 Kbytes. Register R0, R1 and DPTR can be used as a pointer ( indirect addressing) to access data bytes from the external RAM 

MOVX @DPTR, A 

MOVX @Ri, A 
MOVX @R0, A 

MOVX A, @DPTR 

MOVX A, @Ri 
MOVX A, @R0 . 

 Program memory access 


This is the “Read only” type of the data transfer. The data stored in the RAM (either internal or external) are temporary and lost when system is powered down.
 MOVC A, @A+PC
 MOVC A, @A+DPTR 



DATA EXCHANGE 


Exchange instructions as the name suggests, moves data in two directions simultaneously. 
XCH A, Rn // exchange contents of A and Rn 
XCH A, R7 // If A= 10H, R7= 30H, →A=30H, R7=10H 

XCH A, direct // exchange contents of A and address direct 
XCH A, 30H // If A= 10H, (30H)= 20H, →A=20H, (30H)=10H 

XCH A, @Ri // exchange contents of A and address in Ri
XCH A, @R1 // If A= 10H, R1=30, (30H)= 20H, →A=20H, (30H)=10H

XCHD A, @Ri // exchange lower nibble of A and lower nibble of address in Ri 
XCHD A, @R1 // If A= 15H, R1=30, (30H)= 20H, →A=10H, (30H)=25H // higher nibbles of both operands are not affected 




PUSH AND POP INSTRUCTIONS 


PUSH and POP are special instructions that are associated with stack operation. Using these instructions the data is transferred between stack and specified direct address.

 PUSH direct // Increment SP, copy data from address direct to address in SP 
POP direct // copy data from address in SP to address direct, and then // decrement SP For example, 

MOV SP, #50H // initialize SP to point to address 50H 
MOV 35H, #10H // load data 10H in to address 35H 
PUSH 35H // Increment SP to 51H, copy contents of address 35H to address 
                    // 51H i.e. (51H) = 10H 
POP 00H // copy data from address 51H to address 00H, i.e. (00H) =10H // and decrement SP to 50H.






Post a Comment

Previous Post Next Post