Question

2.29 The following is the C codes and the translated MIPS codes. Assume that the C-level...

2.29 The following is the C codes and the translated MIPS codes. Assume that the C-level integers t1 and a0 are held in register $t1 and $a0, and $s0 holds the base address of the integer MemArray.

void foo () {

int MemArray[100] = { 96, 98, 63, 69, 42, 27, 16, 6, 47, 74, 44, 33, 76, 7, 88, 33, 80, 86, 86, 64, 17, 67, 60, 51, 2, 61, 93, 87, 49, 98, 24, 98, 30, 65, 2, 26, 65, 28, 66, 84, 14, 4, 50, 27, 61, 27, 80, 75, 47, 19, 57, 6, 48, 74, 62, 60, 41, 7, 35, 77, 76, 84, 14, 34, 56, 52, 15, 55, 45, 47, 20, 55, 81, 99, 89, 65, 42, 39, 56, 20, 77, 58, 35, 55, 22, 4, 45, 22, 4, 77, 91, 53, 26, 42, 56, 42, 96, 71, 99, 82};

int a0=0;

for (int t1=0; t1<100; t1++) {

    a0 += MemArray[t1];

}

cout << a0 << endl;

}

           

.data

MemArray: .word    96, 98, 63, 69, 42, 27, 16, 6, 47, 74, 44, 33, 76, 7, 88, 33, 80, 86, 86, 64, 17, 67, 60, 51, 2, 61, 93, 87, 49, 98, 24, 98, 30, 65, 2, 26, 65, 28, 66, 84, 14, 4, 50, 27, 61, 27, 80, 75, 47, 19, 57, 6, 48, 74, 62, 60, 41, 7, 35, 77, 76, 84, 14, 34, 56, 52, 15, 55, 45, 47, 20, 55, 81, 99, 89, 65, 42, 39, 56, 20, 77, 58, 35, 55, 22, 4, 45, 22, 4, 77, 91, 53, 26, 42, 56, 42, 96, 71, 99, 82

.text

         la       $s0, MemArray    # s0 = base address of MemArray

         add   $a0, $0, $0         # a0 = 0

         add   $t1, $0, $0           # t1 = 0

LOOP:

         lw    $s1, 0($s0)           # s1 = *MemArray

         add   $a0, $a0,   $s1     # a0 += *MemArray

         addi $s0, $s0,   4         # MemArray++

         addi $t1, $t1,   1        # t1++

         slti    $t2, $t1,   100    # if (t1<100) go to LOOP

         bne   $t2, $0,    LOOP          #

RESULT:

         li       $v0, 1

         syscall

                                               

Rewrite the loop from Exercise 2.29 with memory pointers directly (instead of array) index to reduce the number of MIPS instructions executed.

Hints: You may use the following C codes and translate them to the MIPS codes.

int a0=0;

for ( int* p = MemArray; p<MemArray+100; p++) {

         a0 += *p;

}

         cout << a0 << endl;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the updated code below::

.data

MemArray: .word 96, 98, 63, 69, 42, 27, 16, 6, 47, 74, 44, 33, 76, 7, 88, 33, 80, 86, 86, 64, 17, 67, 60, 51, 2, 61, 93, 87, 49, 98, 24, 98, 30, 65, 2, 26, 65, 28, 66, 84, 14, 4, 50, 27, 61, 27, 80, 75, 47, 19, 57, 6, 48, 74, 62, 60, 41, 7, 35, 77, 76, 84, 14, 34, 56, 52, 15, 55, 45, 47, 20, 55, 81, 99, 89, 65, 42, 39, 56, 20, 77, 58, 35, 55, 22, 4, 45, 22, 4, 77, 91, 53, 26, 42, 56, 42, 96, 71, 99, 82

.text

add $a0, $0, $0 # a0 = 0

add $t1, $0, $0 # t1 = 0

LOOP:

mul $s0, $t1, 4 # get index directly
  
lw $s1, MemArray($s0) # s1 = *MemArray

add $a0, $a0, $s1 # a0 += *MemArray

addi $t1, $t1, 1 # t1++

blt $t1,100,LOOP

RESULT:

li $v0, 1

syscall

output::

li syscall e: 18 Column: 1?Show Line Numbers ars Messages Run l/O 5180 program is finished running (dropped off bottom) -- Clear

Add a comment
Know the answer?
Add Answer to:
2.29 The following is the C codes and the translated MIPS codes. Assume that the C-level...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the below matrixA, which you can copy and paste directly into Matlab.

    Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...

  • The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...

    The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...

  • Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array....

    Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • 1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand....

    1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...

  • Please show how you did this in excel. :13-19 Every home football game for the past...

    Please show how you did this in excel. :13-19 Every home football game for the past eight years at Eastern State University has been sold out. The revenues from ticket sales are significant, but the sale of food, beverages, and souvenirs has contrib- uted greatly to the overall profitability of the football program. One particular souvenir is the football pro- gram for each game. The number of programs sold at each game is described by the following probabil- ity distribution:...

  • Use the pulse rates in beats per minute​ (bpm) of a random sample of adult females...

    Use the pulse rates in beats per minute​ (bpm) of a random sample of adult females listed in the data set available below to test the claim that the mean is less than 82 bpm. Use a 0.05 significance level. Pulse Rate​ (bpm) 96 56 99 95 91 81 61 47 100 78 81 67 76 47 74 57 75 102 66 70 86 47 88 52 44 61 80 91 57 90 73 77 105 105 42 63 93...

  • Use the accompanying data set on the pulse rates​ (in beats per​ minute) of males to...

    Use the accompanying data set on the pulse rates​ (in beats per​ minute) of males to complete parts​ (a) and​ (b) below. LOADING... Click the icon to view the pulse rates of males. a. Find the mean and standard​ deviation, and verify that the pulse rates have a distribution that is roughly normal. The mean of the pulse rates is 71.871.8 beats per minute. ​(Round to one decimal place as​ needed.) The standard deviation of the pulse rates is 12.212.2...

  • Calculate the range, mean, mode, median, Standard deviation Calculate the skewness and kurtosis for the above...

    Calculate the range, mean, mode, median, Standard deviation Calculate the skewness and kurtosis for the above data and interpret the data. The following is data collected from the daily salary employees of ZZ COMPANY.. 68 19 43 11 37 30 19 67 65 34 96 23 93 73 46 39 21 12 89 52 33 21 18 57 80 56 91 62 56 48 84 23 78 96 49 36 90 42 65 15 43 36 65 59 34 71...

  • NUMBER OF PEOPLE 10.2 10.0 10.1 8.5 10.2 8.2 8 Source: United States Census. 11. In...

    NUMBER OF PEOPLE 10.2 10.0 10.1 8.5 10.2 8.2 8 Source: United States Census. 11. In the Sanitary District of Chicago, operating engineers are hired on of a competitive civil-service examination. In 1966, there were 223 appl for 15 jobs. The exam was held on March 12; the test scores are s arranged in increasing order. The height of each bar in the histogram next page) shows the number of people with the correspondin examiners were charged with rigging the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT