0

A,B,C are arrays of length 6, and the base address are found in the registers as follows:

A=[0 1 2 3 4  5], Base = $t0
B=[1 3 5 7 9 11]  Base = $t1
C=[0 5 2 6 3  8]  Base = $t2

And now for the code itself:

add $t4, $zero, $zero
Loop: add $t5, $t4, $t1
      lw $t6, 0($t5)
      add $t5, $t4, $t2
      lw $t7, 0($t5)
      or $t6, $t6, $t7
      add $t5, $t4, $t0
      sw $t6, 0($t5)
      addi $t4, $t4, 4
      slti $t5, $t4, 20
      bne $t5, $zero, Loop

My questions are:

1.) When adding $t4 and $t1, are we adding zero to every B[i]?

2.) When adding arrays in mips, lets say add $t6, $t0,$t1 are we doing:

  • A[i]+B[i] for all the indexes, and then $t6 is a new array?
  • Or are we just doing A[0]+B[0]?

3.) how exactly do you use OR on an array?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
RonaldB
  • 207
  • 1
  • 10
  • *and then $t6 is a new array*? That can't possibly be the case. It's just a 32-bit register. What happens in memory depends on where you store it (with `sw $t6, 0($t5)`, where `$t5` was calculated earlier to point into one of your existing arrays). – Peter Cordes Jul 15 '17 at 19:00
  • Assembly is not like a high-level language where you can process a whole array with a single instruction. That's why this code is inside a loop! – Peter Cordes Jul 15 '17 at 19:01

1 Answers1

1
  1. No, because t4 does not stay zero. Also that's pointer arithmetic, does not deal with the value.
  2. You don't normally do that, adding addresses doesn't make sense usually. There is no such thing in the code.
  3. I don't understand that question. You apply it to the items in a loop. What that means, depends on what the arrays contain.
Jester
  • 56,577
  • 4
  • 81
  • 125