ADDRESSING MODES OF MICRO CONTROLLER

ADDRESSING MODES-MICRO CONTROLLER

All the instruction of 8051 may be classified based on the source type or destination type.
* REGISTER ADDRESSING
* DIRECT ADDRESSING
* REGISTER INDIRECT ADDRESSING
* IMMEDIATE ADDRESSING
* BASE REGISTER + INDEX REGISTER ADDRESSING

The MOV command is used to copy/load a byte from the program , data or internal memory to a processor register or a PORT . The bytes moved is referred to as the operand.A number of addressing modes are used depending on the function required . The general notation of the MOV instruction is

MOV destination, Source

The target / destination may be accumulator A , a register ( R0 to R7) , or internal memory or external memory . Constants may be used as the source, although not all combination are possible.
1,REGISTER ADDRESSING:

The accumulator or register R0 to R7 may be used as the source as well as the target.When register addressing is applied , the register is always one in the currently selected bank.

MOV A,R5 ................>will move the content of R5 to the accumulator.

MOV R5,A .........................> will move the content of accumulator to R5.


2,IMMEDIATE ADDRESSING

This addressing mode is used when a constant is used as the( source ) operand . The assembler recognizes such constant by # (hash) typed in front of them.The constants may be entered in four ways;Decimal , Hexadecimal , Binary , Octal or may be a label.

MOV R2,#54H.....................>will load the given 8 bit data into the specified register.
MOV DPTR, # 8400H.................>will load the 16 bit data into the data pointer.
MOV A , # 65 H.........................>will load the given data into the accumulator.

3,DIRECT ADDRESSING

direct addressing allows access to the lower 128 bytes of the internal RAM and the special function register ( SFRs).The internal RAM is selected when the indicated address is smaller than 128. Else , one of the SFRs is addressed . The accumulator can also be addressed as an SFR at location E0H.

The 16 bit wide data pointer , DPTR makes it possible to address the full 64 K of data and program memory . The DPTR consist of two 8 bit SFRs ; the low byte pointer DPL at 082H and the high byte pointer , DPH at 083H . A special MOV instruction is available to load/initialize the DPTR with a 16 bit value.

MOV 23H,#15.........................>Internal memory location23H is loaded with data 15.
MOV 23H,R5.........................>Register R5 content is copied into location 23H.
MOV A, F0H..........................>content of B register is copied into accumulator.
PUSH F0H ............................>B register content is pushed into stack memory.

4,INDIRECT ADDRESSING

This addressing mode is indicated by @. The required address of the internal RAM is initialized in pointer register R0 or R1.Register R2 to R7 can not be used as pointer to access the internal RAM.For example , to get the data available from internal memory location 45H,into the accumulator, the following instruction may be used.

MOV R0,#45H
MOV A , @ R0

The first instruction is immediate addressing instruction . It places the address 43H in the pointer register R0.The second instruction places the content of the internal memory location 45H into the accumulator.

For example , to get the data from external memory location 5000H, into the accumulator, the following instruction may be executed.

MOV DPTR , #5000H
MOVX A , @ DPTR.

The first instruction is immediate addressing instruction . It places the address 5000H in the data pointer register DPTR.The second instruction copies the content of the external memory location 5000H into the accumulator.

The instruction XCH transfer target to source byte and source to target.

Contrary to direct addressing , it is not possible to access the internal memory address greater than 127 with indirect addressing.

5,PROGRAM MEMORY ADDRESSING

The processor can only read from the program memory , which is normally a ROM or an EPROM . MOV C instruction is used to access program memory , where the C stands for code memory.The target of MOVC is always accumulator.The real address is formed by adding the pointer DPTR or the program counter PC.

MOV DPTR , #5000H
MOV A, # 05H
MOVC A , @A+DPTR

By the first instruction , 5000H is loaded in the DPTR By the second instructions 05 is placed in the accumulator.When the third instruction is executed , the content of the external program memory location 5005H is copied into the accumulator . It can be considered as Indexed addressing mode.The base address is placed in the Data pointer and the offset address in the accumulator .The physical address is the sum of DPTR and Accumulator .Table and fixed texts can be stored permanently in the program memory , and read as and when it required with the aid of DPTR .
However , by using PSEN and RD signals , we can design the chip select circuit to enable external RAM even if MOVC instruction are used .In this contest , the external RAM can be used to store both the program and data.

EXTERNAL DATA MEMORY ADDRESSING

The MOVX (move external) instruction gives access to the external data memory . which is usually RAM available out side the micro-controller . The notation @DPTR is used to get the copy of the specified external memory content.

MOV DPTR , #5000H
MOVX A , @ DPTR
after processing , the processed result available in accumulator may transferred to the external memory by executing the following instructions
MOVX @DPTR,A

XCH INSTRUCTION

Exchange instructions exchanges the data between the accumulator and the byte variable . THe byte variable may be registered Rn or direct of the internal RAM or indirect address of the internal RAM:
XCH A , R5 XCH R5,A
XCH A , 50H XCH 50H,A
XCH @R1,A XCH A , @R1

SWAP INSTRUCTION

It is applicable only for accumulator.It interchange the LOW and HIGH order nibbles of the accumulator . The SWAP instruction is equivalent to executing four times the rotate instruction .

SWAP A RR A RL A
RR A RL A
RR A RL A
RR A RL A

BIT MANIPULATION INSTRUCTION

The content of the carry flag is copied to any specified bit location addressed by the instruction or to the port.

MOV bit-operand, Cy
MOV P1.5, Cy

similarly , the content of the specified bit can also be brought to the carry flag , MOV Cy, bit-operand.

................................................................................................................................................................
........................

Labels: ,