This chapter is continuous of previous chapter 8051 Microcontroller - I.In the previous chapter we have discussed about registers & memory blocks about the 8051.
Let us discuss about addressing mode in 8051.
An "addressing mode" refers to how you are addressing a given memory location. In summary, the addressing modes are as follows, with an example of each:
1.Immediate Addressing:
•An "addressing Immediate addressing is so-named because the value to be stored in memory immediately follows the operation code in memory. That is to say, the instruction itself dictates what value will be stored in memory.
Example:
Let us discuss about addressing mode in 8051.
Adderssing modes:
An "addressing mode" refers to how you are addressing a given memory location. In summary, the addressing modes are as follows, with an example of each:
- Immediate Addressing MOV A,#20h
- Direct Addressing MOV A,30h
- Indirect Addressing MOV A,@R0
- External Direct MOVX A, @DPTRCode
- Indirect MOVC A,@A+DPT
1.Immediate Addressing:
•An "addressing Immediate addressing is so-named because the value to be stored in memory immediately follows the operation code in memory. That is to say, the instruction itself dictates what value will be stored in memory.
For example, the instruction:
MOV A,#20h
MOV A,#0F1h Move the immediate
data byte F1to the A register
MOV DPTR,#0ABCDh Move the immediate
data byte ABCDh to the DPTR
MOV R3,#1C Move the immediate data
byte 1C to register R3
This instruction uses Immediate Addressing because the Accumulator will be loaded with the value that immediately follows; in this case 20 (hexidecimal).
Immediate operands :
The # sign is the designator. These are 8-bits except for DPTR contents (16-bits).Immediate addressing is very fast since the value to be loaded is included in the instruction. However, since the value to be loaded is fixed at compile-time it is not very flexible.
2.Direct Addressing:
Direct addressing is generally fast since, although the value to be loaded isn’t included in the instruction, it is quickly accessible since it is stored in the 8051s Internal RAM.
It is also much more flexible than Immediate Addressing since the value to be loaded is whatever is found at the given address--which may be variable.Example:
MOV
R0,12h Copy
data from RAM location 12h to register
R0
MOV
8Ch,R7 Copy data from register R7
Timer 0 high byte
MOV 5Ch, A
Copy data from register A to RAM location 5Ch
3.Indirect Addressing:
Indirect
addressing is a very powerful addressing mode which in many cases provides an
exceptional level of flexibility
Indirect addressing appears as follows:
MOV
A,@R0
This instruction causes the 8051 to
analyze the value of the R0 register. The 8051 will then load the accumulator
with the value from Internal RAM which is found at the address indicated by R0.
Designated as @Ri,
where i is
0 or 1, uses the contents of R0 or R1 in the selected Register Bank to specify
the address. Other form is @A, using Accumulator contents.
Examples
MOV A,@R0 Copy the contents of the address in R0 to the A register
MOV @R1,#35h Copy the number 35 h to the
address in R1
MOV @R0,80h Copy the contents of the port 0 pins to the address
in R0
MOV add,@R0 Copy the contents of the
address in R0 to add
MOV @R1, A Copy the contents of A to the address in
R1
4.External
Direct:
External
memory can also be accessed using a form of indirect addressing which I call
External Indirect addressing. This form of addressing is usually only used in
relatively small projects that have a very small amount of external RAM.
8051 Instruction Set:
Here is the very very simple summarized table of instruction set.
Mnemonic | Description | Byte | Cycle |
---|---|---|---|
ADD A,Rn | Add register to accumulator | 1 | 1 |
ADD A,direct | Add direct byte to accumulator | 2 | 1 |
ADD A, @Ri | Add indirect RAM to accumulator | 1 | 1 |
ADD A,#data | Add immediate data to accumulator | 2 | 1 |
ADDC A,Rn | Add register to accumulator with carry flag | 1 | 1 |
ADDC A,direct | Add direct byte to A with carry flag | 2 | 1 |
ADDC A, @Ri | Add indirect RAM to A with carry flag | 1 | 1 |
ADDC A, #data | Add immediate data to A with carry flag | 2 | 1 |
SUBB A,Rn | Subtract register from A with borrow | 1 | 1 |
SUBB A,direct | Subtract direct byte from A with borrow | 2 | 1 |
SUBB A,@Ri | Subtract indirect RAM from A with borrow | 1 | 1 |
SUBB A,#data | Subtract immediate data from A with borrow | 2 | 1 |
INC A | Increment accumulator | 1 | 1 |
INC Rn | Increment register | 1 | 1 |
INC direct | Increment direct byte | 2 | 1 |
INC @Ri | Increment indirect RAM | 1 | 1 |
DEC A | Decrement accumulator | 1 | 1 |
DEC Rn | Decrement register | 1 | 1 |
DEC direct | Decrement direct byte | 2 | 1 |
DEC @Ri | Decrement indirect RAM | 1 | 1 |
INC DPTR | Increment data pointer | 1 | 2 |
MUL AB | Multiply A and B | 1 | 4 |
DIV AB | Divide A by B | 1 | 4 |
DA A | Decimal adjust accumulator | 1 | 1 |
ANL A,Rn | AND register to accumulator | 1 | 1 |
ANL A,direct | AND direct byte to accumulator | 2 | 1 |
ANL A,@Ri | AND indirect RAM to accumulator | 1 | 1 |
ANL A,#data | AND immediate data to accumulator | 2 | 1 |
ANL direct,A | AND accumulator to direct byte | 2 | 1 |
ANL direct,#data | AND immediate data to direct byte | 3 | 2 |
ORL A,Rn | OR register to accumulator | 1 | 1 |
ORL A,direct | OR direct byte to accumulator | 2 | 1 |
ORL A,@Ri | OR indirect RAM to accumulator | 1 | 1 |
ORL A,#data | OR immediate data to accumulator | 2 | 1 |
ORL direct,A | OR accumulator to direct byte | 2 | 1 |
ORL direct,#data | OR immediate data to direct byte | 3 | 2 |
XRL A,Rn | Exclusive OR register to accumulator | 1 | 1 |
XRL A,direct | Exclusive OR direct byte to accumulator | 2 | 1 |
XRL A,@Ri | Exclusive OR indirect RAM to accumulator | 1 | 1 |
XRL A,#data | Exclusive OR immediate data to accumulator | 2 | 1 |
XRL direct,A | Exclusive OR accumulator to direct byte | 2 | 1 |
XRL direct,#data | Exclusive OR immediate data to direct byte | 3 | 2 |
CLR A | Clear accumulator | 1 | 1 |
CPL A | Complement accumulator | 1 | 1 |
RL A | Rotate accumulator left | 1 | 1 |
RLC A | Rotate accumulator left through carry | 1 | 1 |
RR A | Rotate accumulator right | 1 | 1 |
RRC A | Rotate accumulator right through carry | 1 | 1 |
SWAP A | Swap nibbles within the accumulator | 1 | 1 |
MOV A,Rn | Move register to accumulator | 1 | 1 |
MOV A,direct | Move direct byte to accumulator | 2 | 1 |
MOV A,@Ri | Move indirect RAM to accumulator | 1 | 1 |
MOV A,#data | Move immediate data to accumulator | 2 | 1 |
MOV Rn,A | Move accumulator to register | 1 | 1 |
MOV Rn,direct | Move direct byte to register | 2 | 2 |
MOV Rn,#data | Move immediate data to register | 2 | 1 |
MOV direct,A | Move accumulator to direct byte | 2 | 1 |
MOV direct,Rn | Move register to direct byte | 2 | 2 |
MOV direct,direct | Move direct byte to direct byte | 3 | 2 |
MOV direct,@Ri | Move indirect RAM to direct byte | 2 | 2 |
MOV direct,#data | Move immediate data to direct byte | 3 | 2 |
MOV @Ri,A | Move accumulator to indirect RAM | 1 | 1 |
MOV @Ri,direct | Move direct byte to indirect RAM | 2 | 2 |
MOV @Ri, #data | Move immediate data to indirect RAM | 2 | 1 |
MOV DPTR, #data16 | Load data pointer with a 16-bit constant | 3 | 2 |
MOVC A,@A + DPTR | Move code byte relative to DPTR to acc | 1 | 2 |
MOVC A,@A + PC | Move code byte relative to PC to acc | 1 | 2 |
MOVX A,@Ri | Move external RAM (8-bit addr.) to A | 1 | 2 |
MOVX A,@DPTR | Move external RAM (16-bit addr.) to A | 1 | 2 |
MOVX @Ri,A | Move A to external RAM (8-bit addr.) | 1 | 2 |
MOVX @DPTR,A | Move A to external RAM (16-bit addr.) | 1 | 2 |
PUSH direct | Push direct byte onto stack | 2 | 2 |
POP direct | Pop direct byte from stack | 2 | 2 |
XCH A,Rn | Exchange register with accumulator | 1 | 1 |
XCH A,direct | Exchange direct byte with accumulator | 2 | 1 |
XCH A,@Ri | Exchange indirect RAM with accumulator | 1 | 1 |
XCHD A,@Ri | Exchange low-order nibble indir. RAM with A | 1 | 1 |
CLR C | Clear carry flag | 1 | 1 |
CLR bit | Clear direct bit | 2 | 1 |
SETB C | Set carry flag | 1 | 1 |
SETB bit | Set direct bit | 2 | 1 |
CPL C | Complement carry flag | 1 | 1 |
CPL bit | Complement direct bit | 2 | 1 |
ANL C,bit | AND direct bit to carry flag | 2 | 2 |
ANL C,/bit | AND complement of direct bit to carry | 2 | 2 |
ORL C,bit | OR direct bit to carry flag | 2 | 2 |
ORL C,/bit | OR complement of direct bit to carry | 2 | 2 |
MOV C,bit | Move direct bit to carry flag | 2 | 1 |
MOV bit,C | Move carry flag to direct bit | 2 | 2 |
ACALL addr11 | Absolute subroutine call | 2 | 2 |
LCALL addr16 | Long subroutine call | 3 | 2 |
RET | Return from subroutine | 1 | 2 |
RETI | Return from interrupt | 1 | 2 |
AJMP addr11 | Absolute jump | 2 | 2 |
LJMP addr16 | Long iump | 3 | 2 |
SJMP rel | Short jump (relative addr.) | 2 | 2 |
JMP @A + DPTR | Jump indirect relative to the DPTR | 1 | 2 |
JZ rel | Jump if accumulator is zero | 2 | 2 |
JNZ rel | Jump if accumulator is not zero | 2 | 2 |
JC rel | Jump if carry flag is set | 2 | 2 |
JNC rel | Jump if carry flag is not set | 2 | 2 |
JB bit, | rel Jump if direct bit is set | 3 | 2 |
JNB bit, | rel Jump if direct bit is not set | 3 | 2 |
JBC bit, | rel Jump if direct bit is set and clr bit | 3 | 2 |
CJNE A,direct,rel | Compare direct byte to A and jmp ifn't equal | 3 | 2 |
CJNE A,#data,rel | Compare immediate to A and jump ifn't equal | 3 | 2 |
CJNE Rn,#data rel | Compare immed. to reg. and jump ifn't equal | 3 | 2 |
CJNE @Ri,#data,rel | Compare immed. to ind. and jump ifn't equal | 3 | 2 |
DJNZ Rn,rel | Decrement register and jump ifn't zero | 2 | 2 |
DJNZ direct,rel | Decrement direct byte and jump ifn't zero | 3 | 2 |
NOP | No operation | 1 | 1 |
Continue to Next.."Timers and Counters"
No comments:
Post a Comment