lecture5

Compile by hand if g h goto less use this mapping

Info iconThis preview shows page 1. Sign up to view the full content.

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: $t1) #$t1=A[i] add $s1,$s1,$t1 #g=g+A[i] add $s3,$s3,$s4 #i=i+j bne $s3,$s2,Loop# goto Loop # if i!=h Loops in C/Assembly •  There are three types of loops in C: –  while –  do… while –  for •  Each can be rewriien 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 mul4ple ways of wri4ng a loop in MIPS, condi4onal branch is key to decision making Inequali4es in MIPS •  Un4l now, we’ve only tested equali4es (== and != in C). General programs need to test < and > as well. •  Create a MIPS Inequality Instruc4on: – “Set on Less Than” – Syntax: slt reg1,reg2,reg3 – Meaning: if (reg2 < reg3) reg1 = 1; else reg1 = 0; – In general, “set” means “set to 1”, “reset” means “set to 0”. Inequali4es in MIPS •  How do we use this? •  Compile by hand: –  if (g < h) goto Less; •  Use this...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 64 taught by Professor Zheng during the Fall '09 term at UCSB.

Ask a homework question - tutors are online