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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Lecture</strong> 9 Translation of <strong>for</strong> while loop statements<br />

Problem<br />

Translate the following high level language instruction into MIPS assembly language<br />

Loop : g = g+A[i]<br />

i = i+j<br />

if (i h) goto loop<br />

Page | 44<br />

Solution<br />

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

g h i j A 4<br />

<br />

$17 $18 $19 $20 $5 $10<br />

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

mult $19 $19 $10<br />

loop: lw $9 $5($19)<br />

add $17 $17 $9<br />

add $19 $19 $20<br />

bne $19 $18 loop

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

Saved successfully!

Ooh no, something went wrong!