What is an addressing mode? Explain different types of addressing mode with ex.
The addressing mode is the method to specify the operand of an instruction. The job of a microprocessor is to execute a set of instructions stored in memory to perform a specific task. Operations require the following:
For example, if we wanted to add the numbers 1 and 2 and get a result, mathematically we would likely write this as 1 + 2. In this case, our operator is (+), or the addition, and our operands are the numbers 1 and 2.
In a microprocessor, the machine needs to be told how to get the operands to perform the operation. The effective address is a term that describes the address of an operand that is stored in memory. There are several methods to designate the effective address of those operands or get them directly from the register. These methods are known as addressing modes.
With immediate addressing mode, the actual data to be used as the operand is included in the instruction itself. Let's say we want to store operand 1 into a register and then add operand 2. With immediate addressing mode, the data values 1 and 2 would be part of the instruction itself as shown below.
When using direct addressing mode, the address of the operand is specified in the instruction. The processor will retrieve the data directly from the address specified in the instruction. In this figure, the example shows how the instruction tells the processor where to get the data from in memory. The variable addr_of_2 is a pointer to the effective address of the operand.
There are no calculations required to retrieve the operand since the effective address (the address of the operand) is addressed directly. Like immediate addressing mode, the operand is limited to the size of 1 word (8 or 16 bits).
Register addressing mode indicates the operand data is stored in the register itself, so the instruction contains the address of the register. The data would be retrieved from the register.