Download
cs61c discussion 3 mips n.
Skip this Video
Loading SlideShow in 5 Seconds..
CS61C – Discussion 3 MIPS PowerPoint Presentation
Download Presentation
CS61C – Discussion 3 MIPS

CS61C – Discussion 3 MIPS

1182 Views Download Presentation
Download Presentation

CS61C – Discussion 3 MIPS

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. CS61C – Discussion 3MIPS

  2. 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

  3. 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,

  4. 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

  5. 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

  6. 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

  7. Control (Loops) • Loops are formed using jumps/branches back to a previous line of code.

  8. 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

  9. Your New Best Friend! MIPS Green Sheet

  10. Worksheet Time • Work with a partner • Try the 1st, 2nd, 4th problems on the front!

  11. 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”

  12. Worksheet Time • Work with a partner • Try the streqproblem on the back!