Addressing Modes Of 8051 Microcontroller Complete Easy Way

Addressing Modes Of 8051

Hi everyone! Welcomes to my article This is the article of addressing modes of 8051

In this article, we will discuss the addressing modes of 8051.

This is the first step towards programming in 8051. 

Instructions can classify based on addressing modes. Addressing modes refer to data.

How data is the address? How data accessed? 

Data is access, it is a part of the instruction, saved in the register or memory. Data on which operation performed.

Following addressing modes of 8051. 

  • Direct Register addressing mode. 

  • Indirect addressing Relative.

  • Immediate addressing mode. 

  • Absolute addressing mode. 

  • Long addressing mode. 

  • Indexed addressing mode. 

  • Bit inherent. 

  • Bit direct addressing.

let’s discuss these modes in detail. First of all, we have the

Register Addressing

We have register addressing which means registers hold the data for operation. R0-R7 registers used here for one operand Example is MOV A, R0. 

These registers are from the current selection of the register bank. We have to address modes to access data from memory.

In this addressing mode, in the instruction the memory of address is specified .

which gives the location, from which data accessed.

For example MOV A, 60H. Here 60H is the memory location from which data will copy to Accumulator.

Immediate Addressing 

Immediate addressing means data is part of the instruction.

For example, MOV A, #30H, here # indicates immediate addressing mode. 30H copied into the accumulator.

Indirect Addressing

In Direct addressing, we can have a memory address from 00H to FFH. Memory address is indirect In indirect addressing. 

In this register The memory address saves. 

From which data is to accessed MOV A, @R0, where R0 contains the memory address from which data will copy to register A.

Ro, R1, and DPTR registers used to hold the memory address in Indirect addressing.

Indexed Addressing

The program counter or Data pointer. Use to hold the base address and A used to hold the offset address.

The Base plus offset address gives the actual address. Data is copied to accumulator. 

Indexed addressing used with instructions of JMP or MOVC . In this slide, we are discussing addressing modes used with a jump and call instructions. 

Relative addressing:

Relative addressing used with Short jump and conditional Jump instructions.

This address is of 8 bits. which added to the program counter to generate the address for branching. 

Thus most address range possible is +127 to -128 locations in short Jump.

Absolute Addressing

We have absolute addressing used with AJUMP(absolute Jump) and ACALL (absolute call). Instruction is a 2 Byte. 

Here 11 bit address taken from the instruction and the upper 5 bits specified by the Program counter.

Long Addressing

So, we can branch up to 2K locations using AJMP or ACALL In long addressing, we have LJUMP & LCALL Instructions. The instruction A total 16-bit address specified . 

These are 3-byte instructions. Thus, branching is possible anywhere in the 64K memory space.

We have addressing modes used for Bit manipulation. 

This is a very important feature of a microcontroller. where we have instructions for bitwise operation.

They are bit inherent and bit direct addressing in bit inherent addressing.

The bit implied in the opcode that is the address of the instruction. 

Whereas in a bit of Direct addressing, In the instruction the direct address of the bit specified . 

For example CLR 07H, here 07H is the address of the bit to be clear by this instruction.

The RAM location 20H to 2FH is a bit addressable memory where these instructions can use. We have discussed addressing mode in this article.

Instruction set for programming of 8051 

Transfer instructions such as Data, 

  • Logical data set Instruction. 

  • Arithmetic data set Instruction. 

  • Branching data set Instruction.

  • Bit Manipulation data set instruction.

We will see all these instructions in detail. We will start with instructions of data transfer. 

These instructions used to copy data from source to destination.

We have instructions for moving the contents between register A and Rn. This is register addressing.  

we have instructions to Move Immediate 8-bit data to register A to register Rn or memory location.

Instructions used to move the contents of a memory location to Rn. Rn to a memory location using direct Addressing. 

Here n stands for 0 to 7 i.e. R0 to R7. In the last category, we have indirect addressing instructions. Here X stands for external memory.

So we use these instructions for data transfer between External Memory and A.

We have PUSH and POP instructions Used for Stack Operation. 

To save the data on stack or to retrieve the data from the stack.

Then we have exchange instructions to exchange byte.

The exchange takes place between the content of the accumulator and register memory.

XCHD instructions used to Exchange the lower order nibble of Accumulator (A0-A3).

With internal lower RAM location.

Then we have MOVC instruction. which used for Moving the content of Program memory to A.  

Coming to arithmetic instructions.

we have addition instruction to Add the contents of A with immediate data.

Or add the content of A with register Rn or Add the contents of A with contents of memory.

Here we have addition operation without carry using ADD instruction. Or with carry using ADDC instruction.

This operation affects CY, AC, and OV flags. on the same lines, we have subtraction instruction.

The difference is content will subtract subtraction takes place. between the immediate data and accumulator. 

Subtraction takes place between the accumulator and Register Rn. Subtraction takes place between Accumulator and memory location.

This operation also affects CY, AC, and OV flags. Then we have a lot of operations. 

In multiplication operation contents of register A &amp. B multiplied and the result stored in both the registers, lower-order byte in A, and higher-order byte in the B register. 

In division operation, contents of A register has divided by the contents of register B.

The result save in register A and the rest saved in register B. DAA stands for (Decimal Accumulator). 

When we added two Binary numbers, the result in binary. This result can convert to BCD using DAA instruction. 

Then we have decrement and increment operation. increment operation increments the data by one. 

decrement operation decrements it by 1. If the contents are FFH, increment operation makes the content 00H but this doesn’t set carry flag.

If the contents are 00H, decrement operation makes the content FFH but this doesn’t set borrow (Carry flag).

logical instructions include ANDing, ORing in this slide.

These instructions used to perform ANDing or ORing operation. Accumulator with immediate data or register or memory location.

Also, instructions are available for operation between memory and immediate data also.

Here the destination stores in the result. whereas the operation performs between source and destination. 

We have an XORing operation.

The operation performs between the source to the destination. And the result stores in the destination. 

For example, we have XRL A,# data so EXORing will take place between A and Data. And in the register A, result will store. 

Then we have complementing instruction here complement of register A.

Or complement carry or complement bit, whose address specified in the instruction.

Logical instruction is for Swapping. This instruction swaps lower and higher nibble of register A.

Then we have rotate instruction rotate accumulator and rotate accumulator with carrying.

We have both rotate left and rotate right instruction.

Rotate with carrying instruction modifies. Carry and shift carry either to LSB or MSB position depending on the left or right rotation. 

coming to branching JUMP instruction. 

we have a short jump absolute jump and long jump. 

We have discussed on addressing Modes Short jump ranges from to +127 to -128 locations. Absolute jump within 2k locations and long jump can be anywhere in 64K address Range.

Incall instructions, we have an absolute call and long call.

Call instruction has RET instruction associated. With it to return back to the main routine. 

RETI stands for return from interrupt. This instruction used to return from interrupt subroutine to the main program. 

short jump instructions are one more category of the conditional jump instruction. 

Here instructions check for a specific bit or carry or accumulator. contents if the condition met, it jumps to a specified location.

All these jump instructions are called short jump instructions. 

We have bit manipulation instructions to operate on individual bits.

At first, we can logically AND the carry bit with other bit or complement of the other bit specified by its address. 

we have Ring instructions. Then we have clear and set instruction, for carrying and for a specific bit.

Whose address mention. Wherever bit mention, it specifies the address of the specific bit of instruction.

That is MOV C, Bit & MOV Bit, C to move the contents of carrying to the bit or vice-versa. 

These are the answers to questions of Part IX on MEMORY INTERFACING

We discuss all instruction. Now we are ready for the programming of addressing modes of 8051. 

Thank you so much for reading this article Please share, and read more blogs of utechblogger

Spread Your Love

Leave a Comment