2.4 For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively.
sll $t0, $s0, 2 # $t0 = f * 4
add $t0, $s6, $t0 # $t0 = &A[f]
sll $t1, $s1, 2 # $t1 = g * 4
add $t1, $s7, $t1 # $t1 = &B[g]
lw $s0, 0($t0) # f = A[f]
addi $t2, $t0, 4
lw $t0, 0($t2)
add $t0, $t0, $s0
sw $t0, 0($t1)
sll $t0, $s0, 2 # $t0 = f * 4 add $t0, $s6, $t0 # $t0 = &A[f] sll $t1, $s1, 2 # $t1 = g * 4 add $t1, $s7, $t1 # $t1 = &B[g] lw $s0, 0($t0) # f = A[f] addi $t2, $t0, 4 # $t2 = &A[f+1] lw $t0, 0($t2) # $t0 = A[f+1] add $t0, $t0, $s0 # $t0 = A[f+1] + A[f] sw $t0, 0($t1) # B[g] = A[f+1] + A[f] Answer: B[g] = A[f+1] + A[f]
2.4 For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the...
I AM POSTING MY QUESTION 3RD TIME . FIRST TWO TIMES I DIDNOT GET THE PROPER ANSWER. PLEASE DO ALL STEPS BY LABELING THE EACH STEP. THIS IS THE ASSIGNMENT IN WHICH THE EACH STEP SHOULD BE LABEL . I MEAN EVERY THING SHOULD BE WRITTEN WHAT WE HAVE DONE IN OUR PROGRAM THIS IS THE REQUIREMENT OF TEACHER , PLEASE DO IT PROPERLY 1) MIPS to C. Assume that the variables f, g, h, i, and j are assigned...
The relative time ratings of exercises are shown in square brackets after each exercise number. On average, an exercise rated [10] will take you twice as long as one rated [5]. Sections of the text that should be read before attempting an exercise will be given in angled brackets; for example, <1.3> means you should have read Section 1.3, Under the Covers, to help you solve this exercise. 2.1 [5] For the following C statement, what is the corresponding MIPS...
Please answer the following questions involving MIPS assembly code: A) For the C statement below, what is the corresponding MIPS assembly code? Assume f, g are stored in S1 and S2. f = g + (-f -5) B) For the C statement below, what is the corresponding MIPS assembly code? Assume i and j are assigned in registers S1 and S2 respectively and base of address of arrays A and B are in registers S6 and S7. B[8] = A[i...
2.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. Assume that the elements of the arrays A and B are 4-byte words: fAlBg
1. For the MIPS assembly instructions below, what is the corresponding C statement? max: lw $t0, 0($a0) #load the first array value into $t0 addi $t1, $0, 1 #intialize the counter to one loop: beq $t1, $a1, exit #exit if we reach the end of the array addi $a0, $a0, 4 #increment the pointer by one word addi $t1, $t1, 1 #increment the loop counter lw $t2, 0($a0) #store the next array value into $t2 slt $t3, $t0, $t2 beq ...
Assignment 3 Translate the following MIPS code to C. Assume that the variables f, g, h, i and j are assigned to registers Ss0, Ss1, Ss2, Ss3 and Ss4, respectively. Assume that the base address of the arrays A and B are in registers Ss6 and $s7, respectively. addi St0, Ss6, 4 add $t1, $s6, $0 #register $0 always holds 320s sw St1, 0(Sto) add Ss0, St1, Sto
Please comment the MIPS code to help me understand.
Here is what the code accomplishes.
Here is the code, partially commented.
.data
Matrix: .word 41,45,5, 34,8,
15,16,23,44,48,12,32,18,47,22,8,22
.word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3
.word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14
.word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7
.word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46
.word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40
.word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4
.word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7
.word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46
.word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3
.word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19
.word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27
.word 48,9,...
Compiling C Programs into MIPS Assembly and Machine Code sll $t1, $a1, 2 add $t1, $a0. $t1 lw $t0, 0($t1) lw $t2, 4($t1) sw $t2, 0($t1) sw $t0, 4($t1) 1. From the assembly code, what machine code might a MIPS assembler produce? 2. What does this program do? Write the C code for this assembly program.
The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of using stack for storing/protecting registers. What is the mistake and how should it be fixed? Correct the corresponding lines in the code. For the corrected code, sketch the stack frame contents at the time when the instruction ‘move $s1, $a1’ is being executed. f: addi $sp, $sp, 12 sw $ra, 8($sp) sw $s1, 4($sp) sw $s0, 0($sp) move $s0, $a0 move $s1, $a1 #...
1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...