Hi,
In MIPS instructions are divided into three types. They are R, I
,J. Every instructions starts with a 6 bit opcode. The R type
instruction is for Registers, I type is for Immediate and J type is
for Jump instructions. Given Below the format and their examples in
detail.
R-Type
format:
- Here op is an operation code that selects a specific
operation.It is 6 bits.
- rt and rs are the first and second source registers.Both are 5
bits.
- rd is the destination register.It is 5 bits.
- shamt is the shift amount and is only used for shift
instructions.It is 5 bits.
- func is used together with op to select an arithmetic
instruction.It is 6 bits.
For example:
The add mnemonic can be used as add $s1, $s2, $s3
here the values of $s2 and $s3 are added together and the result
is stored in $s1.
I-Type
format:
- Load ,store ,branch and immediate instructions are I-type.
- rs is a source register.An address for loads,and stores , or an
operand for branch and immediate arithmetic instructions.
- rt is a source register for branches, but a destination
register for the other I type instructions.
- Here op is 6 bits, rs and rt are 5 bits and and address is 16
bits.
For example:
suppose we want to load from address 0x100a0004 then the
instruction will be
lui $at ,0x100a
lw $t1, 0x0004($at)
Example for branch instructions are: For branch instruction ,
the constant field is not an address, but an offset from the
current PC or program counter to the target address.
beq $at, $s0, L
J-Type
Format:
- The Jump instructions uses j type format.
- The opcode has 6 bits and address has 26 bits.
- Jump instruction has a word address not an offset.
- Each MIPS instruction is one word long and word address must be
divisible by 4, so instead of saying "jump to address 4000" it is
enough to just say "jump to instruction 1000".
- A 26 bit address field allows for jumps to any address from 0
to
-1.
for example : jr $ra it jump to 32 bit address in register
$ra.
Hope you help this.
Thank you...