Professional Documents
Culture Documents
______________________________________________________________________________________
_________________________________
BERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO
______________________________________________________________________________________
Fall 2012
Chuah
EEC70
#under .data
temp: .word
#under .text
sll temp, y, 3 # equivalent to y*8
sll y, y, 1
# equivalent to y*2
add y, y, temp # y*8 + y*2 = y*(8+2) = y*10
6. Translate the following C program into SAL
/* This probram prints the value of the nth fibonacci number */
int main(void) {
int n;
int current=0;
int next=1;
int twoaway;
.data
prompt1:
prompt2:
n:
current:
next:
twoaway
i:
.text
__start:
loop:
puts prompt1
get n
bge i,n outahere
Chuah
outahere:
EEC70
add twoaway,current,next
move current,next
move next,twoaway
add i,i,1
b loop
puts prompt2
put current
done
7. Write a SAL program segment that takes an integer at a memory location labeled number,
multiplies the integer by 100ten, and stores the result at a memory location labeled bigger. For
this program you may not use the SAL mul instruction and you may not use a loop (ie, no
branches allowed). Hint: this multiply can be done by executing 5 SAL instructions.
number:
bigger:
temp:
__start:
.data
.word 12345 # the input number
.word # the result
.word
.text
sll bigger,number,6 # 64 times number
sll temp,number,5 # 32 times number
add bigger,bigger,temp # 96 times number
sll temp,number,2 # 4 times number
add bigger,bigger,temp # 100 times number
done