lecture5

Slt t0 s0 s1 t01 sltu t1 s0 s1 t10

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: mapping: –  g: $s0, h: $s1 Inequali4es in MIPS •  Final compiled MIPS code: slt $t0,$s0,$s1 # $t0 = 1 if g<h bne $t0,$0,Less # goto Less # if $t0!=0 # (if (g<h)) Less: •  Branch if $t0 != 0 (g < h) – Register $0 always contains the value 0, so bne and beq ooen use it for comparison aoer an slt instruc4on. Inequali4es in MIPS •  Now, we can implement <, but how do we implement >, <= and >= ? •  We could add 3 more instruc4ons, but: –  MIPS goal: Simpler is Beier •  Can we implement <= in one or more instruc4ons using just slt and the branches? •  What about >? •  What about >=? Immediates in Inequali4es •  There is also an immediate version of slt to test against constants: slti C! M
 I
 P
 S! – Helpful in for loops if (g >= 1) goto Loop Loop: . . . slti $t0,$s0,1 # $t0 = 1 if #$s0<1 (g<1) beq $t0,$0,Loop # goto Loop # if $t0==0 # (if (g>=1)) What about unsigned numbers? • there are unsigned inequality instruc4ons: sltu, sltiu • which set result to 1 or 0 depending on unsigned comparisons •  $s0 = 0xFFFF FFFA, $ s1 = 0x0000 FFFA •...
View Full Document

Ask a homework question - tutors are online