MIPS pseudo-direct addressing takes the upper four bits of the program counter, concatenated with the 26 bits of the direct address from the instruction, concatenated with two bits of 0 0:
PC31...PC28 IM25...IM00 0 0
which creates a complete 32-bit address. This format is used by the J-type instructions, j and jal. 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.
The reason for forcing the bottom two bits to 0 is that all instruction addresses in MIPS are 32-bit word aligned, so you can never have a target address of a jump instruction with the two bits anything other than 0 0.
- LW loads a word from memory into a register.
- SW saves a word from a register into RAM.
To copy from one register to another you would typically perform an operation which resulted in the data of one register being copied intact into the other register, such as:
or $s2, $zero, $t1
That has the effect of ORing the value in $t1 with the value in $zero (which is always zero), the result of which is $t1 unmodified, which is then placed in $s2.
MIPS can be confusing as there is no instruction specifically for copying from one register to another, but then that's the essence of RISC - why have a MOVE instruction when you can perform the same operation with an OR? It just wastes instructions.
Most assemblers have a collection of macros to make your life easier. You may well find that yours has support for a virtual MOVE instruction, as well as others. Some expand to just one instruction, but some expand to more than one, such as "li", which usually expands to something along the lines of:
lui $t1, %HI(val)
ori $t1, $t1, %LO(val)
I.e., load the upper 16 bits into $t1, then OR the lower 16 bits over the top of it.
Best Answer
Addition sign is for relative addressing not concatenation. $PC=$PC +I*4; means that program counter will point from itself by I*4 locations.
"What is maximum branch distance?" If we look beq or bne instruction, OP, RS, RT, OFFSET = 32bits. For offset is reserved 16bits so the maximum branch distance is 2^16=65535. Sometimes 2^16 is not enough to reach location jump and than you may use unconditional jump.
"What is the maximum offset from $s" I beleive the answer is the same 2^16.