here's a simplistic diagram of the current instruction register inside a central processing unit it holds the program instruction that's currently being executed there are 16 bits shown here but a modern PC processor will employ more the diagram tells us something about the anatomy of a machine code instruction each instruction includes a fixed number of bits to represent the operation such as add subtract load or store the so-called operation code there's also a fixed number of bits to identify the operand or the operands that will be operated upon an operand could be a value a CPU register or a memory address this is also sometimes referred to as the address field for a given sized instruction register if more bits are allocated to the operation code then more different commands are available the Machine can have a larger instruction set but a richer instruction set means that fewer bits are available for the operand which means that fewer memory locations can be accessed directly conversely if fewer bits are used for the operation code then there'll be fewer types of instruction available but more bits available for the memory addresses to help overcome the limitations placed on the amount of memory that can be addressed a processor will have a number of different addressing modes not only this but addressing modes give assembly code programmers and compilers efficient ways to utilize the processors registers and the memory in this diagram you can see that two bits of the operation code have been allocated to indicate the addressing mode the addressing mode tells the process of how the bits in the operand should be interpreted for the purposes of this discussion commands will be shown in the style of an assembly language rather than the ones and zeros of machine code this is reasonable because one assembly language command corresponds to one machine code command the syntax of each assembly code command will be an indication of the addressing mode being employed here you can see a diagram of the central processing unit and some of its registers on the left the main memory is shown on the right with an area for program code and an area for data the processors program counter is pointing to location 100 so this location contains the next instruction to be fetched this particular instruction will load the value 5 into the processors accumulator register when it's executed the accumulator isn't shown in the diagram we're more interested in the fetch part of the cycle it's the hash symbol in front of the 5 that indicates it should be interpreted as a hard-coded value when the operand of an instruction is the actual value to be operated on this is known as immediate addressing to fetch the instruction the address in the program counter is copied to the memory address register then the instruction is copied from memory into the current instruction register via the memory data register the program counter is incremented after the fetch so that it's ready for the next instruction the important point is that once the processor has fetched this instruction the data it needs to work with is available immediately the processor won't need to go back to memory again if the operand is a memory address that contains the value to be operated on it's known as direct addressing which is also sometimes referred to as absolute addressing with direct addressing mode the compiler will have already calculated the effective memory address to be used and written this into the machine code this instruction has just been fetched into the current instruction register notice how the program counter has now been incremented the purpose of this instruction is to load the contents of location 501 into the accumulator so at the start of execution the number 6 is retrieved from memory into the memory data register if the operand is a memory address of a location that contains the effective memory address the mode is known as indirect addressing needless to say this is slower than direct addressing because it means accessing the memory more than once but this does make more memory locations addressable than otherwise might be as indicated by the parentheses this instruction which has just been fetched will look in memory location 501 for the address of the location that contains the data it needs during the execution of this instruction the memory has to be accessed twice if the operand is a processor register we have what's known as register mode if the register contains a value then it's more precisely known as register direct mode register direct mode is very fast because there's no need for the processor to access the main memory after the instruction has been fetched this instruction which has just been fetched will load the contents of general purpose register r1 into the accumulator there's no need to go to memory for this value it's already available if the operand is a register containing a memory address this is known as register in direct mode you can see that this instruction does indeed need to access the memory but only once the speed is therefore similar to memory direct addressing with relative addressing the effective memory address is calculated by taking the operand and adding it to the address in the program counter in other words the program counter contains a base address and the operand is an offset to this the target of a jump also known as a branching instruction can be specified relative to the jump instruction itself an advantage of this is that the jump instruction is independent of its position in memory a program can be loaded anywhere in the memory when it starts without the need to adjust the addresses of jump instructions the current instruction register shown here contains an unconditional jump instruction which makes use of relative addressing when it's executed the operand value 3 will be added to the 101 in the program counter to calculate that the target of the jump is the instruction at memory location 104 the address in the program counter is updated first so that it's pointing to location 104 then control is passed to the new instruction in this case an instruction to add the contents of register r1 to the value in the accumulator with indexed addressing the operand is a base memory address and the effective memory address is calculated by adding to it the value in a processor register known as the index register the index register is denoted here by the letter X indexed addressing is particularly useful when accessing the contents of contiguous memory locations that is what was originally an array variable in the source code by incrementing the contents of the index register which is normally done within a loop the elements of an array can be accessed sequentially here you can see the contents of an array variable in memory the instruction adds 3 to address 500 which contains the fourth element of this zero-based array the number 7 to summarize if the operand is the actual value to be operated on by the instruction this is known as immediate addressing if the operand is a memory address that contains the value to be operated on it's known as direct addressing which is also sometimes called absolute addressing if the operand is a memory address that contains the effective memory address the mode is known as indirect addressing needless to say this is slower than direct addressing because it means accessing the memory more than once if the operand is a processor register containing a value we have what's known as register direct mode this is the fastest form of addressing among all of the addressing modes because there's no need for the processor to access main memory and then move the value into a register the data is right where it needs to be if the operand is a register containing a memory address this is known as register indirect mode with relative addressing the memory address in the program counter that is the address of the next instruction to be fetched is used as a base address the operand is an offset which is added to this in order to calculate the effective memory address this mode is used by jump instructions with indexed addressing the operand is a base memory address and the effective memory address is calculated by adding it to the value in the index register indexed addressing is particularly useful when working with array variables there are other addressing modes depending on the machine architecture for example there are three variations of indexed addressing which include indexed direct as just described indexed immediate and indexed indirect something similar is displacement mode which uses a register containing a memory address instead of the index register some architectures have Auto increment and auto decrement modes and some have a spec addressing mode only the most common addressing modes have been described here