Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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...

1 answer below »
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:
Answered Same Day Nov 29, 2021

Solution

Gaurav answered on Dec 01 2021
136 Votes
Problem -1
    .data
str:    .asciiz "Hello, World!"    
    .text
main:
    la $a0, st
    li $v0, 4
    syscall        # printf    
    li $v0, 10
    syscall        # exit
Problem -2
        .data
esult: .space 400        # result[100] in words
    .text
main:
    la $t0, result        # address of the result
    li $t1, 0        # i = 0
loop:    
    sw $t1, 0($t0)        # result[i] = i
    addi $t0, $t0, 4    # result += 4
    addi $t1, $t1, 1    # i++    
    ble $t1, 100, loop    # while(i...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here