1/37
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
add $t0, $s1, $s2
$t0 = $s1 + $s2
Add values in two registers
sub $s0, $t0, $t1
$s0 = $t0 - $t1
lw $t0, 32($s3)
32 = offset, $s3 = base register, $t0 = source register
$t0 = arr[8]
Load word from memory at address $s3 + 32 into $t0
sw $t0, 48($s3)
48 = offset, $s3 = base register, $t0 = source register
Store word from register $t0 into memory at address $s3 + 48
addi $s3, $s3, 4
$s3 = $s3 + 4
Add constant to a regsiter
$zero
constant 0, can’t be overwritten
$t0 - $t7 - reg’s 8-15
$t8 - $t9 - reg’s 24-25
$s0 - $s7 - reg’s 16 - 23
Register numbers (Temporary values [caller-saved] and Saved values [callee-saved])
op | rs | rt | rd | shamt | funct
special | #s1 | $s2 | $t0 | 0 | add
0 | 17 | 18 | 8 | 0 | 32
000000 | 10001 | 10010 | 01000 | 00000 | 100000
000000100011001001000000001000002 = 0232402016
R-format Example:
add $t0, $s1, $s2
$s1 = 17, $s2 = 18, $t0 = 8, add = 32
sll $t0, $t1, 2
Shift left # $t0 = $t1 << 2
srl $t0, $t1, 1
Shift right # $t0 = $t1 >> 1
and $t0, $t1, $t2
andi $t0, $t1, immediate (constant)
Bitwise AND # $t0 = $t1 & $t2
or $t0, $t1, $t2
ori $t0, $t1, immediate (constant)
Bitwise OR # $t0 = $t1 | $t2
nor $t0, $t1, $t2
nor $t0, $t1, $zero
Bitwise NOT # $t0 = !($t1 | $t2)
beq rs, rt, L1
if (rs == rt) branch to instruction labeled L1
bne rs, rt, L1
if (rs != rt) branch to instruction labeled L1
j L1
unconditional jump to instruction labeled L1
li $v0, 10
syscall
Trigger system call to exit program. AKA Exit: …
sll $t1, $s3, 2 # Temp register $t1 = i * 4
Multiply the value $s3 by 4 and store it in $t1.
slt $t0, $s1, $s2
bne $t0, $zero, L
if ($s1 < $s2)
branch to L
slt rd, rs, rt #sltui = unsigned comparison
if (rs < rt) → rd = 1; else rd = 0
slti rt, rs, constant #sltu = unsigned comparison
if (rs < constant) → rt = 1; else rt = 0;
slt $t0, $s0, $s1 # signed
sltu $t0, $s0, $s1 # unsigned
-1 < +1 → $t0 = 1
+4,294,967,295 > +1 → $t0 = 0
ble $s1, $2, Label
bgt $s1, $2, Label
bge $s1, $2, Label
s1 <= s2 → Label
s1 > s2 → Label
s1 >= s2 → Label
1. Place parameters in registers
2. Transfer control to procedure
3. Acquire storage for procedure
4. Perform procedure’s operations
5. Place result in register for caller
6. Return to place of call
Procedure Calling
• $a0 – $a3: arguments (reg’s 4 – 7)
• $v0, $v1: result values (reg’s 2 and 3)
• $t0 – $t9: temporaries
• Can be overwritten by callee (calling program)
• $s0 – $s7: saved
• Must be saved/restored by callee
• $gp: global pointer for static data (reg 28)
• $sp: stack pointer (reg 29)
• $fp: frame pointer (reg 30)
• $ra: return address (reg 31)
Register Usage
jal ProcedureLabel
Procedure call: jump and link
jr $ra
Procedure return: jump register
mul t0, t1, t2
t0 = t1 * t2
op = 0×00
register-to-register operations.
e.g., add, addu, sub, subu, and, or, slt, sltu, sll, srl, jr, nor
R-type instructions
op(6), rs(5), rt(5), rd(5), shamt(5), funct(6)
op ≠ 0×00, 0×02, 0×03
use immediate values for loads, stores, and branches
e.g., lw, sw, beq, bne, addi, addiu, andi, ori
I-type instructions
op(6), rs(5), rt(5), immediate(16)
op = 0×02, 0×03
Used for jumps with a 26-bit target address
e.g., j & jal
J-type instructions
op(6), constant/address(26)
op ≠ 0×00, 0×02, 0×03
Used to branch to instructions
e.g., bne, blt, beq, etc.
Branch Addressing (I-type instruction)
op(6), rs(5), rt(5), constant/address(16)
move $t0, $t1
blt $t0, $t1, L
Psuedoinstructions:
add $t0, $0, $t1
slt $at, $t0, $t1
bne $at, $0, L
jal Function
jr $ra
Call a function (jump and link)
Return to instruction where call was made (continue)
lb rt, offset(rs)
lbu rt, offset(rs)
load a byte from memory, placing it in the rightmost 8 bits of a register.
#Read byte from source
sb rt, offset(rs)
lui, rt, constant
Load Upper Immediate
Copies 16-bit constant to left of 16 bits of rt
Clears right 16 bits of rt to 0
Load 32 bit constant into register $s0
lui $s0, 61
ori $s0, $s0, 2304
0000 0000 0011 1101 0000 1001 0000 0000
0000 0000 0011 1101 0000 0000 0000 0000
0000 0000 0111 1101 0000 1001 0000 0000