[英]Copying arrays in MIPS32 assembly
I have a segment of C++ code that I need to convert to mips using direct translation. 我有一段C ++代码,我需要使用直接翻译将其转换为mips。 I have most of it done, its a do while loop. 我已经完成了大部分工作,这是一个do while循环。 I just don't understand this one line in MIPS. 我只是不了解MIPS中的这一行。
x[i] = y[i];
I don't understand how to convert this into mips and I've been searching endlessly online. 我不知道如何将其转换为mips,并且我一直在网上不断搜索。 Could I get any help? 我可以帮忙吗?
EDIT 编辑
This is what I had but was told it was incorrect: 这是我所拥有的,但被告知这是不正确的:
la $6, y
Li $7, $1
Add $7, $7, $7
Add $7, $7, $7
Add $8, $6, $7
Lw $6, 0($8)
La $7, x
Li $8, $1
Add $8, $8, $8
Add $8, $8, $8
Add $7, $7, $8
Sw $6, 0($7)
I used this online site as reference: 我使用此在线站点作为参考:
http://www.cs.pitt.edu/~xujie/cs447/AccessingArray.htm http://www.cs.pitt.edu/~xujie/cs447/AccessingArray.htm
SECOND EDIT 第二编辑
C++ Coding C ++编码
i=0;
do {
x[i]=y[i];
i++;
}
while (i!=j);
MIPS Direct translation MIPS直接翻译
Addi $1, $1, 0
Loop: la $6, y
Li $7, $1
Add $7, $7, $7
Add $7, $7, $7
Add $8, $6, $7
Lw $6, 0($8)
La $7, x
Li $8, $1
Add $8, $8, $8
Add $8, $8, $8
Add $7, $7, $8
Sw $6, 0($7)
Addi $1, $1, 1
Bne $1, $2, loop
And here are all my registers I can use to avoid confusion to you: 这是我可以用来避免与您混淆的所有寄存器:
Variables i j x y 4 (constant) Free
Registers $1 $2 $3 $4 $5 $6, $7, $8
This should get you into the right direction. 这应该让你进入正确的方向。 Since this is a homework question, I'm not going to give you a complete solution. 由于这是一个家庭作业问题,因此我不会为您提供完整的解决方案。
Quick Reference (MIPS instructions, calling convention, etc): 快速参考(MIPS指令,调用约定等):
http://www.mips.com/media/files/MD00565-2B-MIPS32-QRC-01.01.pdf http://www.mips.com/media/files/MD00565-2B-MIPS32-QRC-01.01.pdf
An example assembly function that computes the dot product of a 32-bit and a 16-bit vector in a little-Endian environment: 一个示例汇编函数,用于在little-Endian环境中计算32位和16位向量的点积:
http://code.google.com/p/mips32-asm/source/browse/dot32x16.S http://code.google.com/p/mips32-asm/source/browse/dot32x16.S
Here you can see how the elements of arrays are accessed. 在这里,您可以了解如何访问数组的元素。
Note that ".set reorder" makes the assembler reorder the instructions and/or include NOPs to deal with the so-called delay slot. 注意,“。set reorder”使汇编器对指令重新排序和/或包括NOP以处理所谓的延迟槽。 In case your professor wants to see that you understood the delay slot issue, you should order the instructions yourself properly and/or write your own NOP after a branch/jump. 如果您的教授希望您了解延迟插槽的问题,则应该自己正确订购说明和/或在分支/跳转之后编写自己的NOP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.