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.

In real MIPS, word starts at an address that is a multiple of 4<br />

to get the proper byte address<br />

multiply the index by 4,<br />

Add offset to 4 x (2)<br />

A + (4x2)<br />

Page | 40<br />

Problem<br />

Translate HLL statement g = h + A[2] to Assembly<br />

g = h + A[2] means Add the 2 nd<br />

the result in register g<br />

array element to content of register h and store<br />

Solution<br />

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

g h A 2<br />

<br />

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

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

add $t 1 $S 4 $S 4 2+2<br />

add $t 1 $t 1 $t 1 2(2+2)<br />

add $t 1 $S 3 $t 1 Memory address of A + 8<br />

lw $t 0 0($t 1 ) load word from memory address A + 8 to register t0<br />

add $S 1 $t 0 $S 2 add the content of t0 to $s2

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

Saved successfully!

Ooh no, something went wrong!