Transcript for:
Understanding Addressing Modes in Computing

Hello friends, welcome to Gate Smashers In today's video, we are going to discuss what is an addressing mode and what are the types of addressing mode If we talk about computer organization and architecture then addressing mode is one of the most important topic because if you talk about any competitive exam or if you talk about college or university level exam then there also you will definitely get the question of addressing mode and it is a very simple topic First in this video I am going to tell you what is addressing mode What are the benefits of addressing mode and what it is providing us and then what are the types of addressing mode which we will explain one by one So here if we talk about what is an addressing mode So if we talk about instruction which we are discussing about in the previous videos So generally in instruction what we have in instruction Opcode and operand What is operand generally? Operand means data Means which data you have to work on and what is opcode? Operation Means plus, minus, multiplication Now on what you will do plus minus multiplication? Will do on data only Like we write programs in simple C A is equal to 10, int B is equal to 20 C is equal to A plus B Means we are doing addition or subtraction So the data which we pass This data What we are saying about operand is actually We are talking about data But if we talk about an instruction If we talk about any micro-instruction Then in instruction we don't have data directly What can we have? The address of that data can be Means the data which we are bringing in the computer Whatever data is coming, which we are passing in the programs That data is either saved in our memory Or that data is saved in our registers So what we are writing operand here Whatever data we are writing here Whatever bits we are writing here What are those bits actually representing? Are they directly representing data? Or are they representing some address of memory? Or are they representing some number of register? What is that actually? We get to know from addressing mode So addressing mode basically tells us That how to treat these operand bits Means how to consider them This actually tells us addressing mode So here if we talk We can give direct data here Or we give the address that we generally give here Why? Because if we talk about programming Then in programming we work on variables We work on constant If we are giving directly constant In any C program we are giving direct constant value Let's say we are giving the value of constant Pi Now what is the value of Pi? It is constant Now if you are giving this constant value Then you can give that data directly in the instruction But generally we work on variables We can also work like this in variables Like if I have data A is equal to B * C Now here when will A come A value will come when we execute B * C Means when this instruction will be executed After that I will get to know the A value Now this A value How can I give it in the instruction? When I will get to know after the execution of the instruction That what is the value of A Then we can never give the value of data Directly in the instruction Means you can't write directly Subtraction 2 Or subtraction 3 Or multiplication 4 What do we actually give? We work on variables So whenever we talk about variables in programs Or we ask the user for data many times We write scanf So scanf is when we ask the user for data At run time When the program runs and is executed At that time we take data from the user So for these type of instructions We can't give the data directly in the instruction So here I have these bits How we have to treat them How to consider them That actually tells us Addressing mode So generally the variables we have They are generally saved in our memory Whatever data they have Or where they are saved They are saved in the registers So there we have the data given in operand Is it address? Is it the number of the register? These bits how to consider This tells us addressing modes So addressing modes are different types of addressing modes Which I have written here Implied, immediate, register, indirect, direct Auto increment, decrement, direct addressing mode Relative address mode Indexed addressing mode, base register So if we talk about the risk environment If we talk about the risk systems Reduced instructions So there we have Near about 4 to 5 or 5 to 6 addressing modes But the CISC computers Means the complex instruction computers There we have many times Many addressing modes It depends In different computers Different computer organizations Different addressing modes can be But generally In the risk system There are 5 to 6 addressing modes Which tell us that these bits Whatever value is written in operand Whatever address is written How to treat it Now if we talk here What is the benefit of addressing mode The first benefit of addressing mode That number of bits We can reduce in the instruction How? Let's say If we have a memory And the size of the memory Let's say 1M Means 1 million words There are 1M words in this whole memory Now in these 1M words Your instruction can be anywhere Your data can be anywhere Now if you give in the instruction Address Where is your data So obviously the size of your address Will be 20 bits Because 1M is the location here So to represent 1M locations How many bits do we use? 20 bits So the space of your address in the instruction Which is the space of operand How many bits will it be? It will be 20 bits And we also have opcode bits So the size of your instruction Will increase So we can keep data in the register If we talk Let's say we have 16 registers Number of registers is 16 So obviously in 16 registers Where can the data be read Any register can have data read So if I want to represent 16 registers in bits How many bits will I use? 4 bits How? From 0 to 15 number of registers Total registers will be 16 And if we want to represent 16 from 0 to 15 How many bits do we use? 4 bits So if we want to reduce the size of the instruction Then we can keep the data in the register And we can pass the register number in operand So how many will be here? How many bits will be here instead of 20 bits? 4 bits So the size of this will be reduced So this basically provides the facility to the programmer That you can reduce the instruction size You can reduce the bits Apart from this If we talk about Let's say we use pointers in our program What is a pointer? Let's say if I say int a is equal to 10 Now what will happen? A variable will be saved in memory And the value in it will be 10 Now this location Let's say the location is 100 Now if I pass the pointer Let's say there is a pointer ptr And what will we do in ptr? We will pass address of a So address of a is 100 So what value will come in ptr? 100 So here we are using the pointer We will go to a location Let's say this is my memory We checked operand The value in operand was 100 We went to 100 location The data in 100 location Is it our direct data? Or is it also an address? We also know this through Addressing mode It may be that the value is 200 Now what to consider 200? Is it an address? Or is it data? If we talk about indirect mode So what does indirect mode say? That yes, this is also a location ahead Means you will have to go to 200 location from here Whatever data is there in 200 location 10, 20 Pick it up and use it So if we want to facilitate pointers here Then we can use the addressing mode here Or if we talk about counters Let's say if we talk about looping There is a for loop, for i is equal to 1 to 10 Now here we want that if For i is equal to 1 to 10 is written And we printf it So what does it mean? Here 1 to 10 automatically increments So automatically for increment and decrement We have a facility in addressing mode Apart from this, indexing If we want to put indexing in the data Then we also have the facility of indexing Indexed addressing mode And apart from this we have relocation Relocation means Let's say I have a data Means the data is in the memory The data is in 100 to 200 Any process is there in 100 to 200 Now in that process Or in those instructions we have written Whatever instruction is written on 100 Let's say go to 170 location Means jump to 170 Now here you will go to 170 Whatever instruction is written You will pick up that instruction But what happens is We use the funda of relocation Means when this process is executed by CPU Or will use it In future if this process comes again Then it is not necessary that it gets the same location It may get a different location Means now it may be between 500 to 600 This process is now fit between 500 and 600 Now here if I write go to 170 Then what will happen? It will go to such an address Which is actually invalid Means go to 170 means According to this question It should have been go to 570 It should have been at 70 But who changes the addresses? To relocate these addresses We also use the concept of addressing mode So addressing mode provides many facilities and benefits That is what Basically if we are using looping Or if we are using pointers Or if we are using variables here All the variables we use The value of the variables is calculated at run time At execution time So if we want to bring the data at that time Then addressing mode only helps there We do not pass data directly in the instruction There are some modes Like there is an immediate mode I will bring them in detail one by one But here I am giving a simple example There are many instructions In which we can also pass direct value But what we write in most of the code We use variables So when the data of variables comes When we run the instruction When one instruction is run After that we get to know the other data So at that time we Can't pass the data inside the instruction So these are different benefits of addressing modes Which help us to execute all these points So now we will see all these modes in detail one by one in the next video Thank you.