 In this video we're going to discuss three of the ABR addressing modes, the simplest ones. So first of all let's describe that an addressing mode is the mechanism that the microprocessor has by which from the instruction certain fields are interpreted in order to access the operands. So it's something that occurs inside the execution of an instruction and this functionality is what the microprocessor used to access the operands. Now before proceeding with the description of the addressing modes let's describe certain notation that we're going to be using. The address of the operand we're going to call it the effective address and we're going to represent it by ad sub e. Then the instruction fields which is what we're going to be looking to interpret we're going to denote them by inst sub f sub i. Registers we're going to refer to them as r sub i and in some cases the field of the instruction is going to encode the name of a register in that case we're going to refer to that register as r sub f sub i. This is the register specified by the field i found in the instruction. And then the access to memory we're going to distinguish it with these two notations p mem for the program memory and then we provide an address in brackets or d mem for accessing the data memory which we know in the ABR architecture we have these two memories. And finally when there is an operation over a register that takes a new value we'll denote it like this r r o v. Okay so let's describe the first simplest addressing mode which is known as register mode and I think it's the most intuitive one. It is very simple you get an instruction remember that an instruction most of them not all of them have 16 bits so we're going to assume the instruction goes from 0 to 15 bits. There is one field in this instruction not necessarily place where you see it here but it could be spread all over the 16 bits and this field over here specifies one particular register from the register file and in that register is where we find the operand. Another way of looking at this now in terms of the notation we just described here the effective address of the operand is specified by the field let's say f sub 1 on the instruction this is what we refer to this field over here and the operand is actually r sub f sub 1 in other words the register the index of which is encoded in this field. An example of this addressing mode very easy for example this instruction r r 12 r 13 has two operands and both of them are being used or are using the register mode addressing mode and again this is the simplest one. Let's look at two other addressing modes that are not so straightforward. The first one is what we call the data direct this is an interesting one because the instruction which is going to have initially 15 bits 16 bits it's going to have a second set of 16 bits so in other words the instruction it's going to be in this case 32 bits let's call it from 0 to 15 16 to 31 and the second group of 16 bits it's going to define a data memory address in other words the data direct addressing mode assumes that after the 16 bits encoded instruction there are another additional 16 bits with an address and this address is going to be taken directly to access the data memory and we're going to find the operand precisely on that location so if we keep using the notation we used before the effective address of the operand in this case it's actually in the program memory in the address specified by the address of the instruction let's denote it like this at sub inst plus one so this expression what he's saying is that I need to get the address of the operand that I'm accessing from the memory position following the current instruction so this is one example in which we take an additional 16 bits from the program memory and we use them to access the data memory therefore the operand we can say following this notation it's going to be located in the data memory in the position specified by that value which is stored in the program memory in the address of the instruction plus one an example of this addressing mode very common it is when we write an instruction like for example LDS R12 and then a label this label over here is using the data direct typically when you write an assembly program this label is going to be previously defined in the data section and what you're doing here is loading in this particular instruction is loading into register 12 the content in data memory specified by this label another way of looking at it this instruction that you're seeing here is encoded in such a way that the first 16 bits encode the operation code LDS and the register R12 and the additional 16 bits here encode the address which is assigned to this label definition on your program now a couple of interesting things or one interesting thing about this instruction is that it performs three memory operations the first one is to fetch or obtain these first 16 bits the second one is to obtain the address that is following the instruction and the third operation is when it access data memory so as you can imagine this type of instruction is going to be slower than the rest because it requires not only the fetch which all instructions have but an additional access to the program memory to get these 16 bits and another one to access the operand the third addressing mode we're going to describe in this video is what we call data indirect now in a data indirect addressing mode the instruction typically now with 16 bits again 0 to 15 it's going to have one field so from that point of view is similar to this one one field encoding one register so it's pointing to the register file but the difference with respect to register mode is that in this register what we find is the address that we're going to take to data memory to find the operand so the reason why this is called data indirect is because even though the instruction has one field encoding something it is not encoding the destination of the operand but in fact it is encoding the register in which we will find the address of the operand so following the notation we used before the effective address of the operand here it's going to be the register specified by the field f1 in the instruction so remember this notation what it's telling us is I take the content of this register and the index of the register it's going to be encoded in certain field instruction and the operand analogously it's going to be located in the data memory in the position specified by our f1 in this notation we always find the operand in these two addressing modes in the memory location specified by the effective address now two interesting special conditions for this instruction the first one is this instruction performs two memory operations the first one is the same one we saw here the fetch operation because it's present in all the instructions is the operation by which these 16 bits are loaded from the program memory into the control logic but the second one is to access the operand the other very important restriction of this instruction is that memory address in AVR data memory address are 16 bits and remember that the register file contains 32 8 bit registers so how do we store 16 bit registers here and in fact the restrictions is that we can only use registers x y and z which are r31 r30 r29 r28 and r27 r26 in other words the address that we use for the data indirect addressing mode it's going to be stored in one of the three registers that the microprocessor uses concatenating two registers of 8 bits and this microprocessor can do it only with these three pairs of registers