Addressing Modes of 8051 microcontroller
An "addressing mode" refers to how you are addressing a given memory location.
- Immediate Addressing MOV A,#20h
- Direct Addressing MOV A,30h
- Indirect Addressing MOV A,@RO
- External Direct MOVX A,@ DPTR
- Code Indirect MOVC A,@A+DPTR
Each of these addressing modes provides important flexibility.
Immediate 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
This instruction uses Immediate
Addressing because the Accumulator will be loaded with the value that
immediately follows. Immediate addressing is very fast since the value to be
loaded is included in the instruction. Direct Addressing However, since the
value to be loaded is fixed at compile-time it is not very flexible.
Indirect Addressing
Indirect addressing is a very
powerful addressing mode which in many cases provides an exceptional level of
flexibility. Indirect addressing is also the only way to access the extra 128
bytes of Internal RAM found on an 8052. Indirect addressing appears as follows:
MOV A,@RO
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 RO:
For example, let's say RO holds
the value 40h and Internal RAM address 40h holds the value 67h. When the above
instruction is executed the 8051 will check the value of RO. Since RO holds 40h
the 8051 will get the value out of Internal RAM address 40h (which holds 67h)
and store it in the Accumulator. Thus, the Accumulator ends up holding 67h.
Indirect addressing always refers to Internal RAM; it never refers to an SFR.
External Direct
External Memory is accessed
using a suite of instructions which use what I call "External.
Direct" addressing. I call it this because it appears to be direct
addressing, but it is used to access external memory rather than internal
memory. There are only two commands that use External Direct addressing mode:
MOVX A,@DPTR
MOVX @DPTR,A
As you can see, both
commands utilize DPTR. In these instructions, DPTR must first be loaded with
the address of external memory that you wish to read or write. Once DPTR holds
the correct external memory address, the first command will move the contents of
that external memory address into the Accumulator. The second command will do
the opposite: it will allow you to write the value of the Accumulator to the
external memory address pointed to by DPTR.
External Indirect
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. An example of this addressing mode is:
MOVX @RO,A
Once again, the valuc of RO is
first read and the value of the Accumulator is written to that address in
External RAM. Since the value of @RO can only be 00h through FFh the project
would effectively be limited to 256 bytes of External RAM. There are relatively
simple hardware/software tricks that can be implemented to access more than 256
bytes of memory using External Indirect addressing; however, it is usually
easier to use External Direct addressing if your project has more than 256
bytes of External RAM,
Amazing post and it's very informative for us Thanks for sharing and if you are looking for graphtec data loggers check here
ReplyDeletehttps://technicalproducts.in/
https://technicalproducts.in/data-logger2/
https://technicalproducts.in/ac-dc-power-supply2/