The prototypical R-type instruction is:
add $rd, $rs, $rt
where $rd refers to some register d (d is shown as a variable, however, to use the instruction, you must put a number between 0 and 31, inclusive for d). $rs, $rt are also registers.
The semantics of the instruction are;
R[d] = R[s] + R[t]
where the addition is signed addition.
You will notice that the order of the registers in the instruction is the destination register ($rd), followed by the two source registers ($rs and $rt).
However, the actual binary format (shown in the table above) stores the two source registers first, then the destination register. Thus, how the assembly language programmer uses the instruction, and how the instruction is stored in binary, do not always have to match.
INSTRUCTION TYPE APPLICATION
When MIPS instructions are classified according to
coding format, they fall into four categories: R-type, I-type, J-type, and
coprocessor. The coprocessor instructions are not considered here.
The classification below refines the classification
according to coding format, taking into account the way that the various
instruction fields are used in the instruction. The details of the execution
activities and the required control signal values depend almost entirely on the
instruction type in this classification.
- Non-Jump R-Type
- Immediate Arithmetic and
Logic
- Branch
- Load
- Store
- Non-Register Jump
- Register Jump
Non-Jump R-Type
Non-jump R-type instructions include all R-type
instructions except jr and jalr. This includes all of the integer arithmetic and bitwise
operations, along with the non-branching compare instructions such as slt, sgt,
and seq. They use the R coding format. The opcode bits are all 0.
31
|
26
|
25
|
21
|
20
|
16
|
15
|
11
|
10
|
6
|
5
|
0
|
op
|
rs
|
rt
|
rd
|
sa
|
fn
|
There is no update beyond the normal increment.
The two source operands are rs and rt.
The ALU operation is determined by the function
field.
There is no memory access for data.
The result from the ALU is written to rd.
Immediate Operand
Most immediate operand instructions perform
arithmetic or logical operations using one operand that is coded into the
instruction. The immediate operand group also includes the comparison
instructions slti and sltiu and the lui instruction. Immediate operand
instructions use the I coding format.
31
|
26
|
25
|
21
|
20
|
16
|
15
|
0
|
op
|
rs
|
rt
|
imm
|
There is no update beyond the normal increment.
The two source operands are rs and the immediate
field. For all instructions except sltiu the immediate field is sign extended.
For sltiu the immediate field is zero extended. This instruction is not
considered in Patterson and Hennessey.
The ALU operation is determined by the opcode.
There is no memory access for data.
The result from the ALU is written to rt.
Branch
Branch instructions conditionally branch to an
address whose distance is coded into the instruction. Branch instructions use
the I coding format.
31
|
26
|
25
|
21
|
20
|
16
|
15
|
0
|
op
|
rs
|
rt
|
imm
|
If the branch condition is true (see ALU
operation),
PC ← PC + 4 + (sign-extended immediate field)<<2.
The two source operands are rs and rt.
The source operands are subtracted for comparison.
There is no memory access for data.
There is no register write.
Load
Load instructions move data from memory into a
register. The address for the load is the sum of a register specified in the
instruction and a constant value that is coded into the instruction. Load
instructions use the I coding format.
31
|
26
|
25
|
21
|
20
|
16
|
15
|
0
|
op
|
rs
|
rt
|
imm
|
There is no update beyond the normal increment.
The two source operands are rs and the sign
extended immediate field.
The two source operands are added to get the memory
address.
A memory read control signal is sent to memory. The
result from the ALU is sent to memory as the address.
The data from memory is written to rt.
Store
Store instructions move data from a register into
memory. The address for the store is the sum of a register specified in the
instruction and a constant value that is coded into the instruction. Store
instructions use the I coding format.
31
|
26
|
25
|
21
|
20
|
16
|
15
|
0
|
op
|
rs
|
rt
|
imm
|
There is no update beyond the normal increment.
The two source operands are rs and the sign
extended immediate field. The rt register is also fetched.
The two source operands are added to get the memory
address.
A memory write control signal is sent to memory.
The result from the ALU is sent to memory as the address. The contents of rt
are sent to memory as the write data.
There is no register write.
Non-Register Jump
The only non-register jump instructions
are j and jal. Non-register jump instructions use the J coding
format.
jr and jalr:
|
PC ←
target address
|
- The target address is the
concatenation of the high order 4 bits of PC + 4, the target field of the
instruction, and two 0 bits.
- Source operand fetch
There is no source operand fetch.
There is no ALU operation.
There is no memory access for data.
j:
|
There
is no register write.
|
jal:
|
$ra ←
PC + 4
|
Register Jump
The only register jump instructions
are jr and jalr. Register jump instructions use the R coding
format. The opcode bits are all 0.
31
|
26
|
25
|
21
|
20
|
16
|
15
|
11
|
10
|
6
|
5
|
0
|
op
|
rs
|
rt
|
rd
|
sa
|
fn
|
The only source operand that is used is the rs
register.
There is no ALU operation.
There is no memory access for data.
jr:
|
There
is no register write.
|
jalr:
|
rd ← PC
+ 4
|
Register Jump
The only register jump instructions
are jr and jalr. Register jump instructions use the R coding
format. The opcode bits are all 0.
31
|
26
|
25
|
21
|
20
|
16
|
15
|
11
|
10
|
6
|
5
|
0
|
op
|
rs
|
rt
|
rd
|
sa
|
fn
|
The only source operand that is used is the rs
register.
There is no ALU operation.
There is no memory access for data.
jr:
|
There
is no register write.
|
jalr:
|
rd ← PC
+ 4
|
prepared by:NOR FADILA BT MOHD YUNUS
B031410253
ADDRESSING MODES
|
MIPS only has a small number of ways that is
computer addresses in memory.
It can be address of an instruction (for branch and jump instructions)
or it can be an address of data (for load and store instruction).
1. REGISTER ADDRESSING: used in jr register instruction
2. PC-RELATIVE ADDRESSING: used in beq and bne instructions
3. Pseudo-direct addressing: used in j instruction
4. Base addressing : used in lw and sw instructions
REGISTER ADDRESSING
§ SIMPLEST ADDRESSING MODE
§ BOTH OPERANDS ARE IN A REGISTER
REGISTER DIRECT ADDRESSING:
§ MOV A, R4
§ At a time registers can take value from R0,R1 to R7,
there are 32 such registers
§ There are 4 registers bank named 0,1,2,3
§ Each bank has 8 register banks from R0 to R7
§ Only one register can be selected
§ Bits are designated from PSW.0 to PSW.7
§ Register banks are selected using PSW.3 and PSW.4
§ These two bits are known as register bank select bits as
they use to select register bank
REGISTER INDIRECT ADDRESSING:
Eg:
add a,[b]
Register b contains an address
The contents of this address are added to the accumulator
Int x = 2;
b = &x;
a += *b;
REGISTER INDIRECT WITH DISPLACEMENT ADDRESSING:
Eg:
add a,[b+10]
Register b contains a number
The desired memory address is 10 plus the contents of b
The contents of this address are added to the accumulator
byte x[20]; /*x is at addr 10*/
b = 5;
a += x[b];
IMMEDIATE ADDRESSING
§ THE OPERAND IS A CONSTANT WITHIN
THE ENCODED INSTRUCTION
§ INSTRUCTIONS WILL BE EXECUTED FASTER
BECAUSE IT DOES NOT INVOLVE MEMORY ACCESS
§ JUMP INSTRUCTION FORMAT ALSO FALLS
UNDER IMMEDIATE ADDRESSING
MOV A, #6AH
§ Opcode for MOV A,# data is 74H
§ Opcode is saved in program memory at 0202 address
§ Data 6AH is saved in program memory 0203
§ When opcode 74H is read, the next step taken
would be transfer whatever data the next program
memory address
§ This instruction is 2 bytes and is executed in one cycle
§ After execution, program counter will add 2 and move
to 0204 of program memory
|
PREPARED BY:WAN NORAQILAH BINTI A.RAZAK(B031410306)
|
No comments:
Post a Comment