Which is one of the core part in MIPS.
Let's have a look at Addressing Modes shall we?
So what is Addressing Modes ?
Addressing Modes are the ways of specifying an operand or a memory address.All right , There are 5 ways of addressing data.
I will first introduce all 5 ways of addressing data. And I will get into each one of them later on.
- Register Addressing
- Immediate Addressing
- PC-Relative Addressing
- Base Addressing
- Pseudo-Direct Addressing
- Register Addressing is considered the simplest addressing mode.
- This is because both operands are in a register. Which allow instructions to be executed much more faster in comparison with other addressing modes because they does not involves with memory access.
- The number of registers is limited since only a few bits are reserved to select a register.
- Register Addressing is a form of direct addressing , this is because we are only interested in the number in the register , rather than using that number as a memory address.
add $s1 , $s2 , $s3 also means that $s1 ←$s2 + $s3
- In immediate addressing , the operand is a constant within the encoded instruction.
- Immediate addressing has the advantage of not requiring an extra memory access to fetch the operand , hence will be executed faster. However , the size of operand is limited to 16 bits.
- The jump instruction format also falls under immediate addressing , where the destination is held in the instruction.
- PC-relative addressing is usually used in conditional branches. PC refers to special purpose register , Program Counter that stores the address of next instruction to be fetched.
- In PC-relative addressing , the offset value can be an immediate value or an interpreted label value.
- The effective address is the sum of the Program Counter and offset value in the instruction. The effective address determines the branch target.
- PC-relative addressing implements position-independent codes. Only a small offset is adequate for shorter loops.
- Branch instructions can only move 32768 above or below the program counter because the offset is a 16-bit two’s complement number.
- Base addressing is also known as indirect addressing , where a register act as a pointer to an operand located at the memory location whose address is in the register.
- The register is called base that may point to a structure or some other collection of data and immediate value is loaded at a constant offset from the beginning of the structure. The offset specifies how far the location of the operand data from the memory location pointed by the base.
- The address of the operand is the sum of the offset value and the base value(rs). However, the size of operand is limited to 16 bits because each MIPS instruction fits into a word.
- The offset value is a signed number which is represented in a two's complement format. Therefore , offset value can also be a negative value.
- Pseudo-Direct addressing is specifically used for J-type instructions , j and jal. The instruction format is 6 bits of opcode and 26 bits for the immediate value (target).
- In Pseudo-Direct addressing , the effective address is calculated by taking the upper 4 bits of the Program Counter(PC) , concatenated to the 26 bit immediate value , and the lower two bits are 00.
- Therefore , the new effective address will always be a word-aligned and we can never have a target address of a jump instruction with the two bits anything other than 0 0 and creates a complete 32-bit address. Since the upper 4 bits of the PC are used, this constrains the jump target to anywhere within the current 256 MB block of code (1/16 of the total 4 GB address space). To jump anywhere within the 4 GB space, the R-type instructions jr and jalr are used , where the complete 32 - bit target address is specified in a register.
thank you for the useful note :)
ReplyDeletechiknaa
ReplyDeleteeasy to understand
ReplyDeleteHoly Hell, so much more informative than the Computer Arch class: notes, book, or even the instructor. A thousand thanks!
ReplyDeleteThanks to share such a useful information with us !
ReplyDeleteThere is a type in your Immediate Addressing example:
ReplyDeleteaddi $t1 , $zero , 1 means $t1 ← 0 + 7
should be:
addi $t1 , $zero , 1 means $t1 ← 0 + 1
Thank U.......
ReplyDeleteWhat is meant by operand??
ReplyDeleteIs the smallest address that Pseudo-Direct Addressing can reach the PC&f0000000(16)? I mean, if current PC is something like 80000000, can you still use j type instructions to jump to any former instruction?
ReplyDeletethank you very much, these topic haven't found anywhere with full description, but here it is
ReplyDeletethank you
ReplyDeleteThank you for the very good and useful article. From IT Service in HoChiMinh CIty
ReplyDelete:(
ReplyDeleteBlahh😭👍
ReplyDelete