lecture4 - CSCI-365 Computer Organization Lecture Note Some...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSCI-365 Computer Organization Lecture Note : Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson & Hennessy, ©2005 Some slides and/or pictures in the following are adapted from: slides ©2008 UCB 4 Loops in C/Assembly • Compile into MIPS; A is an array of int s do { g = g + A [ i ]; i = i + j ; } while ( i != h ); • Use this mapping: g , h , i , j , base of A $s1 , $s2 , $s3 , $s4 , $s5 (done in class) Loops in C/Assembly • There are three types of loops in C: – while – do … while – for • Each can be rewritten as either of the other two, so the method used in the previous example can be applied to while and for loops as well • Key Concept : Though there are multiple ways of writing a loop in MIPS, the key to decision making is conditional branch Inequalities in MIPS • Until now, we’ve only tested equalities ( == and != in C). General programs need to test < and > as well • Create a MIPS Inequality Instruction: – “Set on Less Than” – Syntax: slt reg1,reg2,reg3 – Meaning: if (reg2 < reg3) reg1 = 1; else reg1 = 0; – “set” means “set to 1”, “reset” means “set to 0” reg1 = (reg2 < reg3); Same thing… Register Zero • The number zero (0), appears very often in code • MIPS defines register zero ($0 or $zero ) to always have the value 0; eg add $s0,$s1,$zero (in MIPS) f = g (in C) where MIPS registers $s0,$s1 are associated with C variables f, g Immediates...
View Full Document

{[ snackBarMessage ]}

Page1 / 18

lecture4 - CSCI-365 Computer Organization Lecture Note Some...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online