1 / 13

CS61C – Discussion 3 MIPS

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

necia
Download Presentation

CS61C – Discussion 3 MIPS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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!

More Related