Question: do not write its the same code . # Translate this c statement into MIPS assembly language code. # Assume the arrays hold 32-bit integer
# Translate this c statement into MIPS assembly language code. # Assume the arrays hold 32-bit integer values # $so is the base for array X # $sl is the base for array Y # $t0 and $t1 are index variables i and j, respectively. # x[j] = Y[i + j]; // convert this to MIPS assembly code # 1. Calculate index for variable y, i.e., i + j. into temp register # registers $t0 and $t1 are being used, but we have others # 2. Convert c index into 32-bit (4-byte) offset # 3. Add the offset to the base address of Y to get & (Y[i+jl) # 4. Load the value from &(Y[i + j]) into a temp. register # 5. Convert the c index of x into a 32-bit (4- byte) offset # 6. Add the offset to the base address of x to get & (X[i]) # 7. Store the value from step 4 into X[j] add $t2, $t0, $t1 # $t2 = i + j = c index sll $t2, $t2, 2 # $t2 4*(i+j) = byte offset from Y addu $t2, $sl, $t2 # $t2 = base+offset & (Y[i+j)) lw $t2, 0($t2) # $t2 Y[i+j) sll $t3, $t1, 2 # $t3 = 4* j = byte offset from x addu $t3, $80, $t3 # $t3 base+offset & (X[j]) $t2, 0($t3) # x[i] = Y[i+j] = SW The first question is similar to what we did in class today, i.e., translate C code into MIPS assembly language. I've attached the text file we used during the lecture (C-2-MIPS.txt). The second question is just the opposite of the first, i.e., convert MIPS assembly language into C. On both questions, pay attention to the size of the C variables (8-bits?, 16- bits?, 32-bits?) as it affects the way you get from the C array index to the MIPS offset and vice versa
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
