Question

In: Computer Science

g[8]=4[A[3j] + B[i+6j] I and j are variables. When doing MIPS instructions for above statement what...

g[8]=4[A[3j] + B[i+6j]

I and j are variables. When doing MIPS instructions for above statement what needs to be done to 4[A[3j]? Choose your own temporary and store registers. Explain show step by step

Solutions

Expert Solution

g[8] = 4[A[3j] + B[i+6j]

1. In order to expand the above statement we need to understand the Instruction Set Architecture (ISA) & Memory allocation

Example ( instruction format for load instruction )

lw $to, 4($t1)

// here $to is the destination address, $t1 inside the bracket is the base address and 4 is offset . Lets assume the base //address was 4n then the 4($t1) will correspond to 4n+4.

Please look at the table below for memory allocation  

Memory allocation
4n 4n+1 4n+2 4n+3 4n+4 4n+5 4n+6 4n+7 4n+8 4n+9 4n+10 4n+11 4n+12 4n+13 4n+14 4n+15

|---------- A[0]-----------|--------------A[1]------------|--------------A[2]--------------|-------------A[3]---------------------|

2. Now that we have understood the ISA basics we can proceed to the question g[8] = 4[A[3j] + B[i+6j]

here i & j are variables so if we consider 4[A[3j] it will be expanded as A[3*j] so A[3] will be the base address with some offset to be added

so if we consider i = 1 , j = 1 , value of A will become A[3] with memory constant 12, This output willl be further multiplied with 4

B will become B[1+6] which is B[7] , Memory constant to be added will become 28

Assembly:

lw $t0, 12($s1) // A[3] is brought in to $t0 with constant offset 4 added

ori $t1, $zero, 4 // store immediate value for 4 in 4[A[3j]]

mult $t0, $t0, $t1 // multiply the value by 4

lw $t2, 28($s2) // B[7] is brought into $t1

add $t0, $to, $t2 // added and stored in $t0

sw $t0, 32($s4) // $t0 is stored into g[8]   


Related Solutions

For the following MIPS instructions, (1) show its format or type (I-format, R- format, or J-...
For the following MIPS instructions, (1) show its format or type (I-format, R- format, or J- format); (2) translate them into binary using the follow procedure (Note: $s0-$s7 are the 16-23th registers, $t0-$t7 are the 8-15th registers). For example, addi    $s0, $s1, 2               # the op code of addi is 0010002 Format (?): lw       $s1, 4($s1)               # the op code of lw is 1000112 Format (?): bne     $s1, $t1, loop           # the value of loop here is...
What are these C Codes in MIPS? A[R[j]] = -645 -j /4 A[32] = R[9j] -...
What are these C Codes in MIPS? A[R[j]] = -645 -j /4 A[32] = R[9j] - 4j A base address -> s0 R base address -> s1 j -> t1
1. ¬B∨(G↔J), H→(B&C) ∴(H&J)→G 2. A∨B, C↔¬(B∨D) ∴C→A 3. (A&B) ↔ (F→G), (A&F) & B∴(G→R)→R 4....
1. ¬B∨(G↔J), H→(B&C) ∴(H&J)→G 2. A∨B, C↔¬(B∨D) ∴C→A 3. (A&B) ↔ (F→G), (A&F) & B∴(G→R)→R 4. T→¬B, T→¬D ∴ T→¬(B∨D) 5. ¬(M∨¬S), S→(R→M) ∴A → (¬R∨T) 6. (F&G) → I, (I∨J) → K ∴F→(G→K) 7. ¬U, O→G, ¬(O∨G) →U ∴G Prove that the arguments are valid by constructing a dedication using the rules MP, MT, DN, Conj, Simp, CS, Disj, DS, DM, CP, HS, BE, and DL. Use CP if needed.
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j a. How many bits does it take to encode ? b. How many bits needed in register file to store the data?
There exists a group G of order 8 having the following presentation: G=〈i,j,k | ij=k, jk=I,...
There exists a group G of order 8 having the following presentation: G=〈i,j,k | ij=k, jk=I, ki=j, i^2 =j^2 =k^2〉. Denotei2 bym. Showthat every element of G can be written in the form e, i, j, k, m, mi, mj, mk, and hence that these are precisely the distinct elements of G. Furthermore, write out the multiplication table for G (really, this should be going on while you do the first part of the problem).
Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g +...
Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note that 13 should be calculated, not hardcoded
J-BOND CO issued 700,000 of 8 year bonds at a stated rate of 4% when the...
J-BOND CO issued 700,000 of 8 year bonds at a stated rate of 4% when the market rate of interest was 5%. The bonds were issued on July 1 and paid interest semi-annually.   The issue price of the bonds is The bonds were issued at (premium, discount, par) The entry to record interest expense for period 7 is ( you may use clear abbreviations for the account names) If the company were to repurchase the bonds at 97 at the...
Write a complete ARM asembly program for following code: g=12, h=8, i=2, j=5; f = (g...
Write a complete ARM asembly program for following code: g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note that 13 should be calculated, not hardcoded Below is my current code: .global _start _start: mov R0,#12 mov R1,#8 mov R2,#2 mov R3,#5 add R4,R0,R1 add R5,R2,R3 sub R6,R4,R5 How should I display the message: "f = (g + h) –...
What am i doing wrong. I want for the program to run through then when it...
What am i doing wrong. I want for the program to run through then when it gets to "do you want to play again?enter yes or no" if they choose yes I want it to run again if they choose no then end. def play(): print("Welcome to the Game of Life!") print("A. Banker") print("B. Carpenter") print("C. Farmer") user_input = input("What is your occupation? ").upper() if user_input == "A": money = 100 elif user_input == "B": money = 70 elif user_input...
Using C++ : What am I doing wrong!?!? Problem Instructions: Implement a program that repeatedly outputs...
Using C++ : What am I doing wrong!?!? Problem Instructions: Implement a program that repeatedly outputs an I of a size entered by the user. Prompt the user for a size. If -1 is entered, quit the program. If an even number or a number smaller than 3 is entered, prompt the user again. Then output a shape of # characters that represent an I. Repeat the program until -1 is entered. What I have so far: #include <iostream> #include...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT