0
votes

im having some problems with understanding how to convert instructions to MIPs assembly. the problem is. Write the MIPS assembly for the following instructions. Assume variables a – j are assigned to temporary registers $0 – $8. Assume that the base address of arrays A and D are in $9 and $10. If you need a register to store an intermediate result, you can use any remaining temporary or saved registers or register $at (the assembler temporary register). Convert the assembly codes into machine code

D[i]=A[j]<<6

now , i have it set up like this

  1. 0$
  2. 1$ a
  3. 2$ b
  4. 3$ c
  5. 4$ d
  6. 5$ f
  7. 6$ g
  8. 7$ i
  9. 8$ j

    1. 9$ A
    2. 10$ B

im a confused , because in class , my teacher always started with the SLL (shift logical left) command for the 2 examples we did. my question is do we always do this? im not sure i understand what SLL actualy means/does , so i cant really see if it would benefit this problem. so far i have the firt instruction , this is assuming SLL is the first thing that happens. I thought maybe LW would come first. this is what i got for my answer

  1. SLL $11 , $8 , 6 2.Add $12, $9,$11
  2. lw $13,0($12)
  3. sll $14,$7,2
  4. add $15,$14,$10
  5. sw $13,0(15$)
1
Are those arrays indexed in words or bytes? There are only 10, not 11 temporary registers, and those are $8-$15, $24-$25, not $0-$8. Please, make your question a bit clearer. - user35443

1 Answers

0
votes

Alright, it's quite difficult to understand some of the things you mentioned in your post.

Let's say that you want to turn D[i] = A[j] << 6 into MIPS assembly, knowing that

  • $8 contains the i index
  • $9 contains the j index
  • $10 contains the A array address
  • $11 contains the D array address
  • $12 and $13 can contain anything we want, as temporary registers

We start on the right side, with the operator of the largest priority: []. We know that A + j is the address of element A[j], assuming that j contains a byte offset from array base. Therefore,

add $12, $10, $9  ; $12 = A + j
lw $12, 0($12)    ; $12 = the word at $12 (A[j])

Now we do the shift itself, using sll

sll $12, $12, 6   ; $12 = $12 << 6

Having $12 filled with the calculated right side, we need another register to address D[i]

add $13, $11, $8  ; $13 = $11 + $8
sw $12, 0($13)    ; stores $12 (right side) to $13 (D[i])