简体   繁体   中英

Understanding MIPS assembly Code

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?

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM