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> 7 Data transfer memory register - two instructions<br />

Manipulate data in memory<br />

lw<br />

load word memory to register Register Memory<br />

sw<br />

store word from register to memory Register Memory<br />

I <strong>for</strong>mat<br />

op rs rt address<br />

6 bits 5 bits 5 bits 16 bit<br />

Page | 39<br />

Problem<br />

Consider the array A[] and the HLL statement<br />

g = h + A[8]<br />

Translate it into assembly language.<br />

g = h + A[8] means Add the eighth array element to content of register h and<br />

store the result in register g.<br />

Solution<br />

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

g h A<br />

<br />

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

array A[] is in memory<br />

eighth element of array A A[8] is in memory<br />

starting address of A is in $S 3<br />

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

lw $t 0 8($S 3 )<br />

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

Problem<br />

Translate the HLL statement A[12] = h+A[8] to assembly<br />

A[12] = h + A[8] means Add the content of array element eight to content of<br />

register h and store the result as 12th element of the array<br />

Solution<br />

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

A[12] = h+A[8]<br />

<br />

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

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

lw $t 0 8($S 3 )<br />

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

sw $t 0 12($S 3 )

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

Saved successfully!

Ooh no, something went wrong!