280 likes | 1.87k Views
CS61C – Discussion 3 MIPS. MIPS Fast Facts. Fast and simple RISC or SISC? Reduced Instruction Set Computing How many registers? 32 Hmm… what is a register? Small amount of storage directly on the CPU How big are the registers? 32 bits = 4 bytes Access the registers using $0 to $31
E N D
MIPS Fast Facts • Fast and simple • RISC or SISC? • Reduced Instruction Set Computing • How many registers? • 32 • Hmm… what is a register? • Small amount of storage directly on the CPU • How big are the registers? • 32 bits = 4 bytes • Access the registers using $0 to $31 • Or names: $zero $t1, $s0
MIPS Arithmetic Example intx, y, z; x = 4; y = x*math.pow(2, 4); z = 17; x = x + y-z; addi$s0, $zero, 4 sll$s1, $s0, 4 addi$s2, $0, 17 add $s0, $s0, $s1 sub $s0, $s0, $s2 Some other important arithmetic/logic:sll, srl, slt,
Store/Load & Memory • What happens if we have more variables than registers? • SPILL to memory • Store TO memory • sw $t0, off($t1) • Stores $t0 into mem[$t1 + off] • Load FROM memory • lw $t0, off($t1) • Loads mem[$t1 + off] into $t0 • lb, sblbu– don’t sign extend
Control (Branch) • beq $rs, $rt, offset (branch if $rs==$rt) • bne $rs, $rt, offset (branch if $rs!=$rt) • if (condition satisfied): move {offset} amount of instructions from current oneelse: continue to next line • Almost always branch to a LABEL for legibility • ex: beq $t0, $t1, mylabel
Control (Jump) • j addr (jumps directly to {addr}) • jaladdr (jumps directly to {addr}, stores addr of next inst into $ra) • jr$rs (jumps to the address stored in $rs) • Like branches, we often use labels with j and jal
Control (Loops) • Loops are formed using jumps/branches back to a previous line of code.
Announcements • How was HW2? • HW3-1 (MIPS) Due Wednesday • Proj1-1 Released on Wednesday • TA Kevin made an awesome MIPS helper sheet • See Course Homepage >> Resources >> MIPS Helper Sheet
Worksheet Time • Work with a partner • Try the 1st, 2nd, 4th problems on the front!
Translating C Functions to MIPS • $a0, $a1– arguments to a function • $v0, $v1 – return values from the function • Why are there 2? • jalis used to call a function • Jumps to a label and stores the “return address” into $ra • jr$ratakes you back to where you came from • “Jump to the address in the register $ra”
Worksheet Time • Work with a partner • Try the streqproblem on the back!