View Course Path

Addressing Modes in 8085 Microprocessor

In this post, we’re going to learn about how an 8085 microprocessor accesses data stored in different parts of the memory. We know that the 8085 can access data stored in different parts of the memory using instructions. But how that data is accessed, is what is known as an addressing mode.

To make things simple, let us imagine a colony of warehouses of uniform sizes in a grid formation. Each warehouse has a number allotted to it which is called its address. Also, assume that each warehouse has some goods in it, this will be our data. And every house and the goods stored in it are referred to using the address. The grid shown below will help you to visualize it.

A grid representation of how memory blocks are organised with addresses and store data

Also, there are some special warehouses in the colony which have special names allotted to them. These represent our Registers B, C, D, E, H, and L. And they are organized in pairs.

A representation of 8085 registers organisation

Here is a visual representation of the registers in 8085. Some other registers such as PSW, Stack Pointer are not shown here.

While writing an assembly language program for 8085, we will use various ways to access data stored in the memory and the registers. These are called addressing modes. All this may seem a little intriguing in the beginning, but the examples and code snippets along the way and the analogy used here will enable you to visualize everything.

The following are the different modes of addressing the data stored in memory. Let us look at each of them one by one to get a clear picture.

Immediate Addressing Mode

In this mode, the number directly given by the programmer is moved into the location specified. This location could be a register or an address in the memory. It would be easy to understand through the following example.

MVI A, 25H  ; Save 25H into the Accumulator
MVI C, 62H  ; Save 62H into the C register

In the first statement, we are directly giving a number 25H and telling the microprocessor to move it into the Accumulator Register.

Using the analogy discussed in the starting, you can understand this as telling the microprocessor.

“Hey! Take this good (number 25H) and store it in the warehouse with name A”.

In other words, we can understand the Immediate Addressing Mode as a mode in which an immediate value is given to operate on.

Some other examples are

LXI B, 3050H     ;Load H-L pair with value 3050H. Higher byte 30H goes in H while lower byte 50H goes in L
LXI SP, 4050H    ;Load value 4050H in stack pointer register
JMP 9000H        ;Jump to address 9000H

Notice that the operands of the two LXI instructions are a register pair and the Stack Pointer register whose combined capacity is 2 bytes (16 bits) and hence, we can give a 16-bit number as the second operand. If we give an 8-bit number, the higher 8 bits are assumed to be 00H.

Here are examples of some of the instructions which use immediate addressing mode.

LXI B, 3050H    ;Load H-L pair with value 3050H.
MVI C, 62H      ; Save 62H into the C register
ADI 20H        ;The value 20H is added to the contents of the accumulator.
ACI 34H        ;The value 34H and the carry flag is added to the contents of the accumulator.
SUI 22H        ;The value 22H is subtracted from the contents of the accumulator
SBI 24H        ;The value 24H and the borrow flag is subtracted from the contents of the accumulator

There are some more instructions that use the immediate addressing mode. All such instructions are listed below.

LXI   MVI   ADI   ACI   SUI   SBI   CPI   ANI   XRI   ORI

These instructions may seem to be too many. But you can simply remember them as “The instructions ending with the letter I, which stands for immediate, are the instructions for immediate addressing mode” with one exception though: the JMP instruction.

Register Addressing Mode

In this mode, the data to be accessed and operated upon is present in a register and is accessed by specifying the name of the register.

For example,

MOV A, B ;Save contents of B in Accumulator

This command moves the contents stored inside the B register to the Accumulator.

In terms of the analogy used above, consider that besides the warehouses having numbers as addresses, some special warehouses (registers) also have names. And in this mode, we use the names of warehouses.

The above example can be imagined as telling the microprocessor.

“Hey! I want the goods stored in the warehouse with the name B to be moved to the warehouse with the name A”.

Here are some more examples of Register addressing mode.

ADD B    ;Adds the value stored in B to the value in Accum.
ADC C    ;Contents of register C and carry flag are added to the contents of Accumulator
SUB E    ;Subtracts the value stored in E to that in Accum.
SBB E    ;Contents of register E and carry flag are added to the contents of Accumulator
INR C    ;Increments the contents of register C by 1
INX B    ;Increments the contents of register pair BC by 1

Some more instructions using Register Addressing Mode are given below. To know about each of them in detail, you can check out the posts on the instruction groups of the 8085 in this free 8085 course.

MOV   ADD   ADC   SUB   SBB   INR   INX   DCR   DCX   CMP   ANA   XRA   ORA

Direct Addressing Mode

Consider the grid of warehouses we discussed in the beginning. The warehouses had numbers as addresses. In this mode, we use the corresponding number (address) to refer to a warehouse (memory location).

In other words, we access the data stored in a memory location using its address. Consider the example

LDA 2034H    ;Load the content at memory location 2034H into the Accumulator
LHLD 2040H   ;Load the content at 2040H into register L and contents at the next location 2041H into register H

The first line tells the microprocessor “Load the content of the memory location with address 2034H into the Accumulator”.

In order to understand the second line in the above example better, using the analogy of warehouses, this instruction can be imagined as telling the microprocessor.

“Hey!! I am giving this address 2040H to you. Go to the warehouse at this address. Pick up the contents stored there and load them into the warehouse with name L i.e. register L. After that, go to the next address 2041H and transfer its contents to register H. ”

Here are some more examples to understand this mode of addressing better.

STA 3030H   ;Load the content at memory location 3030H into the Accumulator
SHLD 2040H  ;Load the contents of the register L into memory location with address 2040H and load the
            ;contents of register H at the next memory location 2041H

Register Indirect Addressing Mode

Now, this one is a little trickier to get. But can be easily understood using the analogy we used in the beginning.

In this mode, the register(s) holds the address of the location from which data is to be retrieved. Confused? Consider the following example.

MOV A, M    ;move contents of the memory location whose address is held by HL pair into the Accumulator

You may think of it like this. In the grid of warehouses, there is a warehouse with the name ‘A’. Suppose you have an assistant to move your data around as you want. Now, the command above tells your assistant

“ Go to the pair of warehouses with the name H and L. Read its contents. Those contents will tell you an address; H will tell you the higher 8 bits and L will tell you the lower 8 bits of the address. Then, go to the warehouse at that address. And fetch me the contents stored there. ”

I guess it is clear now. Have a look at the following example to have a more clear picture. If you think you have understood the concept thoroughly, you can just skip the example in the red box and move ahead.

Consider the following lines of instructions.

;Suppose it is known that the number 25H is stored at memory location with address 2030H
MVI H, 20H
MVI L, 30H
MOV A, M ;M stands for memory (i.e HL pair)
MVI M, 92H

After running the above code, what do you think will be stored in the Accumulator? Yes, register A will hold the value 25H. And what will be stored at the location with the address 2030H?

Explanation

  1. After the execution of the first line, register H will have value 20H stored in it.
  2. After the execution of the second line, register L will have value 30H stored in it. So, now we have 2030H stored in register pair HL.
  3. The instruction in the third line tells the microprocessor to look at the address (in the memory) given by the HL pair which is now 2030H. So, the microprocessor looks at the location with address 2030H and loads the content stored there into the accumulator. As we assumed, the memory location with address 2030H had the number 25H stored in it. So, the microprocessor will copy it and paste it in the accumulator. And hence, the accumulator will contain 25H.
  4. In the fourth line of instruction, we tell the microprocessor to move the value given by us, i.e. 92H to the memory location. And the address of the memory location is read from the HL register pair. HL pair still holds the value 2030H. So, the microprocessor will store 25H at the memory location with address 2030H.

So, in the end, the Accumulator will hold the value 25H and the memory location with address 2030H will hold the value 92H.

Here are some more instructions which use this mode of addressing.

ADD M    ;Add contents of the memory location whose address is held by HL pair to the contents of theAccumulator
INR M    ;Add contents of the memory location whose address is held by HL pair is incremented by 1
CMP M    ;16 bit number from HL pair is picked up. Then, contents at the address given by picked up number is
         ;compared with those of the accumulator. The result of the comparison is shown by setting the flags of
         ;the PSW as follows:
         ;* if (A) < (reg/mem): carry flag is set
         ;* if (A) = (reg/mem): zero flag is set
         ;* if (A) > (reg/mem): carry and zero flags are reset
A very important point to note here is that the address of a memory location is of 16-bit size but the data stored in a single memory location is 8 bits. We can think of it as “the address of a warehouse consists of 16-bits, but the storage capacity of the warehouse is 8 bits”. So, instruction ‘STA 3030H’ will load an 8-bit number in the accumulator.

There are some more instructions that use the Register Indirect Addressing Mode. These are listed here.

MOV   MVI   ADD   ADC   SUB   SBB   INR   DCR   CMP  ANA  XRA  ORA

Implied Addressing Mode

In this mode of addressing, the microprocessor already knows the location of data to process and the programmer does not need to define it explicitly. That information is already contained in the opcode. For example,

CMA   ; Each bit of the 8 bit number stored in Accumulator is complemented. Note that in this case, it is implied
      ; that the data to be processed is in the accumulator and we don't need to specify it.
RLC   ; the 8 bits of the number stored in the Accumulator are manipulated in such a way that each bit is moved
      ; left by 1 place and the most significant bit is moved to the least significant position.

The first instruction CMA complements the bits. Using our analogy, we can say that the instruction CMA tells the microprocessor.

“Go to the warehouse with name A. Access the contents stored. The contents will be a packet of 8 bits. Unpack those bits. Complement each bit one by one. If a bit is 1, make it 0 and vice versa. Then put those bits in their corresponding positions, repack them and put them back in the warehouse A”.

The address of data to be manipulated is the register A which is not stated in the instruction. It is already understood by the microprocessor when such instructions (instructions with implied addressing mode) are used.

The second example of instruction RLC is explained through this picture. To get a more in-depth explanation of how this instruction works, you can check out the working of all rotate instructions in 8085 over here.

Some more examples showing implied addressing mode are

CMC    ; The carry flag is complemented
STA    ; The carry flag is set to 1

In both of the above examples, the data to be processed is in the carry flag. We don’t need to specify it. When these two instructions are used, the microprocessor already knows it.

To have a more clear picture and a better understanding of implied addressing mode and the CMA and RLC instructions, read the code snippet in the following red box and the explanation following it. If you think you have got the gist of the concept, you can skip ahead.

Consider the following lines of instructions.

MVI A, 07H
RLC
RLC
RLC
RLC
CMA

What will be the contents of the accumulator after running the above code snippet?

Explanation

  1. In the first line, value 07H is stored in the accumulator. The 8-bit representation of 07H is 0000 0111.
  2. In the second line, bites are rotated left in a circular manner. So, the bits stored in A become 0000 1110. Note that each bit is moved left by one position and the most significant bit is moved to the least significant bit position.
  3. The same operation is repeated and the value stored in the accumulator changes to 0001 1100.
  4. The same operation is repeated a third time and the value stored in the accumulator changes to 0011 1000.
  5. The same operation is repeated for and the value stored in the accumulator changes to 0111 0000. This value in hexadecimal is 70H.
  6. Now, in the sixth line, all bits in the accumulator are complemented. 0111 0000 becomes 1000 1111. This value in hexadecimal is 8FH.

Hence, the correct answer is 8FH.

Instructions using the Implied Addressing Mode are listed here.

RLC   RRC   RAL   RAR   CMA   CMC   STC

Check your understanding!

You can check how much you have understood by answering the following questions.

One thought on “Addressing Modes in 8085 Microprocessor

  1. Thank you for the wonderful explanation! But I noticed this mistake where STA is mentioned for storing a memory location’s value to the accumulator (that LDA does), however it is opposite. STA is used for storing content of accumulator to the mentioned memory location.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.