在 MIPS 汇编中将元素从一个数组复制到另一个数组

发布于 2024-10-19 08:32:25 字数 301 浏览 4 评论 0原文

我是 MIPS 的新手,一直在尝试将元素从一个数组复制到另一个数组。我不确定该怎么做。数组的大小并不重要,但为了这样做,我们只说它的大小为 10。我对 MIPS 循环有点弱,并且对如何继续感到有点困惑。

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

我的初始化是 $s0 是第一个数组中第一个元素的地址,$t0 是第二个数组中第一个元素的地址。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是在用心讲痛 2024-10-26 08:32:25

我不相信你提供的代码是正确的,但假设它是正确的,你会做这样的事情:

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

免责声明:自从大学以来我就没有在 MIPS 中编程过,所以这个代码可能不是 100% 准确,但我相信它会给为您提供一个起点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文