2. Instructions: Language of the Computer > 2-3. Representing Instructions in computer
Representing Instructions in computer
Updated at 2022.09.24
CPU, register, and memory
$0, ..., $31
hold the value that will be used in the operation (called general purpose register)Execution of the instruction
ADD $s0, $s1, $s2
$s1
and $s2
and stores the computation result in $s0
Instructions for arithmetic
Operation | C | Java | MIPS assembly language | Example |
---|---|---|---|---|
Add | + | + | add (R), addi (I) | add $t0, $t1, $t2 |
Subtract | - | - | sub (R) | sub $t0, $t1, $t2 |
Instructions for bitwise manipulation
Operation | C | Java | MIPS assembly language | Example |
---|---|---|---|---|
Bitwise AND | & | & | and (R), andi (I) | and $t0, $t1, $t2 |
Bitwise OR | \ | \ | or (R), ori (I) | or $t0, $t1, $t2 |
Bitwise NOR | ~ | ~ | nor (R) | nor $t0, $t1, $t2 |
MIPS has no NOT instruction
Instead, it has NOR R-type instruction
nor $t0, $t1, $zero
Operation | C | Java | MIPS assembly language | Example |
---|---|---|---|---|
Shift left | << | <<< | sll (R) | sll $s1, $s2, 10 ($s1 = $s2 << 10) |
Shift right | >> | >>> | srl (R) | srl $s1, $s2, 10 ($s1 = $s2 >> 10) |
Operation | MIPS assembly language | Example |
---|---|---|
Conditional branch |
beq (I)bne (I)
|
beq $t0, $t1, LABEL (if $t0 == $t1, goto LABEL) bne $t0, $t1, LABEL (if $t0 != $t1, goto LABEL)
|
Unconditional branch |
j (I)
|
j LABEL (goto LABEL)
|
Instructions for making decisions
Usually combined with goto statements and labels
there are no branch instructions like blt (less than) and bge (greater than or equal to)
Why?
Instead, MIPS provides others
Operation | MIPS assembly language | Example |
---|---|---|
Set on less than |
slt (R), slti (I)sltu (R), sltui (I) for unsigned numbers |
slt $t0, $t1, $t2
|
slt is used in combination with beq and bne
slt $t0, $t1, $t2
bne $t0, $zero, LABEL
beq $t0, $zero, LABEL