简体   繁体   中英

Copying elements from one array to another in MIPS assembly

I'm new at MIPS and have been trying to copy elements from one array to another. I'm unsure about how to go about this. It doesn't really matter what size the array is but lets just say for the sake of doing it that its size 10. I am little weak with MIPS loops and am kind of confused on how to proceed.

add $s0, $zero, $zero
add $t0, $zero, $zero
lui $s0, 0x1001
ori $s0,$s0,0
lui $t0, 0x1001
ori $t0, $t0, 0x0040

There my initialization with $s0 being the address first element in the first array and $t0 being the address of the first element in the 2nd one.

I do not believe the code you have provided is correct, but assuming it is, you would do something like this:

xor $t1, $t1, $t1          ; Zero out $t1
lw $t2, array_length       ; Load the length of the array in $t2
loop_start:

  lb $t3, $s0              ; Load the next byte from $s0 into $t3
  sb $t3, $t0              ; Store the by in $t3 into $t0

  addi $s0, $s0, 1         ; Move to the next byte in the source
  addi $t0, $t0, 1         ; Move to the next byte in the destination
  addi $t1, $t1, 1         ; increment the counter

blt $t1, $t2, loop_start   ; Jump to the start of the loop of there are more bytes

Disclaimer: I have not programmed in MIPS since college so this code may not be 100% accurate, but I believe it will give you a place to start.

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