COMP 122 Problem set 3 (Fall 2018 )
Your Name
COMP 122: Computer Architecture
November 29, 2019
Problem 1.
Convert the following code to MIPS:
1 int main()
2 {
3 printf("Hello, World!");
4 return 0;
5 }
Problem 2.
Convert the following C code to MIPS
1 int result[100];
2 int main ()
3 {
4 int i = 0;
5 for (int i = 0; i <100; i+=0)
6 {
7 result[i] = i;
8 }
9 }
Problem 3.
Convert the following MIPS code to C
1
1 .data
2 Sz: .word 10
3 A
ay: .word 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
4 .text
5 main:
6 lw $t0, Sz
7 move $t1, $zero
8 move $t2, $zero
9
10 back:
11 bge $t1, $t0, end
12 sw $t1, A
ay($t2) #shift
13 addi $t1, $t1, 1
14 addi $t2, $t2, 4
15 j back
16
17 end:
Problem 4.
Unroll the following code (in C)
1 int result[10];
2 int main ()
3 {
4 int i = 0;
5 for (int i = 0; i <10; i+=0)
6 {
7 result[i] = i;
8 }
9 }
Problem 5.
Unroll the following code (in MIPS)
1 .data
2 Sz: .word 10
3 A
ay: .word 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
4 .text
5 main:
6 lw $t0, Sz
7 move $t1, $zero
8 move $t2, $zero
9
10 back:
11 bge $t1, $t0, end
12 sw $t1, A
ay($t2) #shift
13 addi $t1, $t1, 1
14 addi $t2, $t2, 4
15 j back
16
17 end: