05.08.2014 Views

Lecture Notes for Computer Architecture II - St. Cloud State University

Lecture Notes for Computer Architecture II - St. Cloud State University

Lecture Notes for Computer Architecture II - St. Cloud State University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Lecture</strong> 8<br />

Conditional <strong>St</strong>atements If Switch<br />

- beq - branch equal<br />

- bne - branch not equal<br />

- slt - set less than<br />

- j - jump<br />

- jr - jump register<br />

Page | 42<br />

beq $S 1 $S 2 L<br />

means if $S 1 = = $S 2 jump to L<br />

= = means equal<br />

bne $S1 $S2 L<br />

means if ( $s1 = /= $s2) goto L<br />

Problem<br />

Translate the following HLL statement<br />

if (i = = j) f = g+h; else f = g-h;<br />

= means assignment<br />

Solution<br />

<strong>St</strong>ep1 Assign variables to registers<br />

f g h i j<br />

<br />

$S 0 $S 1 $S 2 $S 3 $S 4<br />

<strong>St</strong>ep 2 Do simple translations<br />

A. add $S 0 $S 1 $S 2 f = g+h<br />

B. sub $S 0 $S 1 $S 2 f = g-h;<br />

Now organize the translation<br />

bne $S 3 $S 4 else<br />

A<br />

j exit<br />

else: B<br />

exit:<br />

Completed code<br />

bne $S 3 $S 4 else<br />

add $S 0 $S 1 $S 2<br />

j exit<br />

else: sub $S 0 $S 1 $S 2<br />

exit:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!