Chapter 2
Representing Instructions in the Computers, MIPS Logical Operations and Instructions for Making Decisions
Representing numbers in a word
�Representing instructions in the computer�
Instruction Format
�Translating a MIPS Assembly Instruction into a Machine Instruction�
�MIPS Fields�
Instruction Format
R-Type Instructions
I-Type instruction
Instruction formats
Sample Instructions
R-type and I-type instructions.
Example: Translating MIPS assembly language into machine language
is compiled into
lw $t0, 1200($t1) # Temporary reg $t0 gets A[300]
add $t0, $s2, $t0 # Temporary reg $t0 gets h + A[300]
sw $t0, 1200($t1) # Stores h + A[300] back into A[300]
What is the MIPS machine language code for these three instructions?
Solution
Solution
Solution
Example
Solution
MIPS machine language code
8 | 12 | 15 | 5 |
Machine code
MIPS architecture
Test Your knowledge
���MIPS instructions.���
The stored-program concept
�Logical operations�
Shifts
shamt field in the R-format
AND
�OR�
or $t0, $t1, $t2 # reg $t0 = reg $t1 | reg $t2
The value in register $t0:
0000 0000 0000 0000 0011 1101 1100 0000two
�NOT�
�Instructions for Making Decisions�
branch if equal (beq)
branch if not equal (bne)
Conditional branch
�Compiling if-then-else into Conditional Branches�
if (i == j) f = g + h; else f = g – h;
Solution:
bne $s3,$s4,Else # go to Else if i ≠ j
add $s0,$s1,$s2 # f = g + h (skipped if i ≠ j)
j Exit # go to Exit
Else:sub $s0,$s1,$s2 # f = g – h (skipped if i = j)
Exit: