 video session on addressing modes for peak microcontroller 16F877A, myself Mr. Vipul Kondekar. In this video session, these are the learning outcomes at the end student will be able to which is the addressing mode used for a particular instructions will be able to identify the addressing mode and then describe the three different addressing modes immediate, direct and indirect addressing mode for the peak microcontroller. Now these are the contents we will have brief introduction then immediate addressing, direct and indirect addressing we will try to understand. First let us try to understand what do you by addressing mode. Now whenever you are doing operations by using peak microcontroller maybe some arithmetic operations you are doing you require operand for that. Now how you get operand? Operand may be available in memory may be available in the data memory say one operand may be in the working register itself but another operand suppose is available in the data memory how you are giving the information about the operand whether that operand is available in your instruction itself or if it is available in the data memory where which operand is to be considered how you are giving the information about the operand how to access the operand that is called as addressing mode. Now basically three addressing modes are supported by the peak microcontroller immediate, direct and indirect. Let us try to understand how we can access the operands. Now first simple addressing mode is immediate addressing mode. Immediate addressing mode means the operand information is available in the instruction itself. Now there are two different types of instructions one is general instruction where you are specifying the operand information in the instruction itself and here you will find that that operand information is 8 bit literal value. So that 8 bit operand so that k can take values from 0 to 255. So this 8 bit value is available in the instruction itself or there are instructions like call and go to in these two type of instructions that address you are specifying and in that case that 11 bit value address is available in the instruction itself. So here in this case k will take range from 0 to 2047 2 raise to 11 will correspond to this particular range. So this is immediate addressing where in the instruction itself you will find the operand. Operand may be 8 bit operand if it is a general instruction and if it is a call or go to type of instruction then your operand will be basically part of address itself so that will be of 11 bits. Now let us try to understand what is direct addressing. So direct addressing is what the address is available in the instruction directly. Now basically talking about the data memory organization we know that there we have got four different banks each bank is of 128 bytes. Now basically to have address for each location here uniquely you will require 9 bit address. So what is done in the direct addressing? In the direct addressing we are providing the 7 bit address in the instruction itself. 7 bit address of the operand is available in the instruction itself and then remaining 2 bits are taken from the status register RP0 and RP1 are the 2 bits which are concatenated. So this 7 bits 7 plus 2 9 bits so you will get unique address here. In other words just here by using the address in the instruction you are deciding the offset from this top to bottom and then with that offset in which bank you have to work so that you will get from the RP0 and RP1. So this is how direct addressing work where you have got 4 banks but a particular register in a particular bank will get selected. Bank will get selected because of these 2 bits and remaining 7 bits will decide which location from that particular selected bank will be your operand's address. So this is how the direct addressing works. Where here you will find that for direct addressing this RP0 and RP1 bits are used and then based on these bit values these are the bits of the status register based on these bit values you will can access a particular bank. Next when you go for indirect addressing here just you can see that in indirect addressing IRP bit of the status register is used. So if it is IRP bit is 0 then you can access this bank 01 and if IRP bit is 1 then you can access this bank 2 and 3. Now let us try to understand how indirect addressing works. So in the indirect addressing what is done is in indirect addressing 8 bit address is available in one register called as FSR register. And remaining bit is taken from IRP bit of the status register. So these 8 bits and this 1 bit concatenated to it will form a 9 bit address and from this 9 bit address you can access to any of these locations contents. So this is how basically indirect addressing is done where IRP bit is used. Now for indirect addressing for peak microcontroll is quite interesting. Here we are making the use of one register which is called as INDF register also. Basically INDF is not a physical register but we can use that INDF register in the instruction and then whenever you are using INDF instruction in the instruction then it will be a instruction of kind indirect addressing. Indicative indirect addressing uses that INDF register and then whenever any instruction is using INDF register actually what it access is a register which is pointed by FSR. So FSR will be basically a pointer but in the instruction we will be dealing with the INDF and when you are dealing with the INDF so actual location which your access time to access is the location which is pointed by this FSR register. Now reading INDF registers indirectly if you are trying to read INDF itself through indirect addressing so it will read to 00 and writing INDF register indirectly will result in no operation. So you cannot go for making the use of this INDF register for what we can say this reading or writing we will see how this INDF register can be used. And then an effective 9 bit address is obtained how you get 9 bit address in the indirect addressing is again by concatenating that 8 bits of FSR and this IRP bit of the status register which is the most significant bit. Now this indirect addressing we will try to understand through a simple program. See this program is written for clearing the RAM locations. Now let us try to have one question where we will go through the program try to answer this which RAM locations are cleared due to the execution of the program which is using the indirect addressing mode. Now you will come to know let us go through this program so these are the simple instructions you will see move LW20 this will load 20 into the working register and then move WF FSR means this 20 value will be loaded to the FSR register. Now in the code I am writing CLRF INDF so what you are writing is CLRF INDF clear INDF register but what it clears when you are using INDF in the instruction actually it uses the register which is pointed by FSR. Now FSR is pointing to the address 20 so what gets clear? What gets clear is the contents of the address location this 20 edge. Again in the here I am using INCF FSR so what I am doing is I am pointing I am incrementing that pointer just so if it is 20 initially it will become 21 and then INCF FSR comma F so comma F will say whatever is the result after increment that result will be stored in the FSR register itself so now initially it was 20 it will become 21 and then I use one instruction bit test file which file you have to test FSR and you have to check bit number 4 bit 0 1 2 3 4 so bit number 4 you have to check and if it is set then you have to skip this particular instruction if that bit is set you have to skip the instruction initially it has started with the 20 edge address so for 20 bit number 4 will not be set for 21 bit number 4 will not be set so this next instruction will get executed and if it is set then only it will be skipping this execution means from this you will go for execution of the next program means you can continue with your next program now by looking at this can you tell at what time this particular program will go outside this particular loop so that that other subroutine gets executed indirectly which locations are cleared by this particular program so till the bit number 4 becomes 1 this is this will go on clearing the bits of that address locations 20 21 22 so which addresses which addresses are cleared so here is the answer this will be the program which will be clearing the locations 20 edge to 2f because 2f will make that least significant lower nibble as 11 11 and after this definitely this bit is going to be one and you will come outside the loop so this is how interestingly you can use the indirect addressing where FSR will be actual pointer register in the instruction you are dealing with the INDF but when you are using INDF actually you are using the register which is pointed by FSR and this will be clear to this block diagram again so where if the immediate addressing mode is there you will be finding one later L inside the instruction add LW move LW so L stands for immediate addressing where the operand is available in the instruction itself if it is a direct addressing 7 bit in the instruction remaining 2 bits from the status register and if it is indirect addressing mode then 8 bit information is available in the FSR register itself and remaining 1 bit is taken from the status register this is how you can access the operand from the data memory by using direct or indirect addressing mode so this is how the addressing modes of peak microcontroller works immediate direct and indirect addressing mode these are the references used for this presentation thank you