Closed. This question is off-topic。它当前不接受答案。                                                                                                                                                                                                                                                                                                                        想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。                                                3年前关闭。                                                                                                                    我试图将C代码转换为MIPS程序集。这是一个片段。问题是我不太确定自己是否走正确的路。我希望有人可以提供帮助。这是原始问题:void swap(int v[], int k, int j) {int temp;temp = v[k];v[k] = v[j];v[j] = temp;}这就是我走了多远:swap:addi $sp, $sp, -4sw $s0, 0($sp)add $s0, $zero, $zeroL1: add $t1, $s0, $a1lb $t2, 0($t1)add $t3, $s0, $a0sb $t2, 0($t3)beq $t2, $zero, L2addi $s0, $s0, 1j L1L2: lw $s0, 0($sp)addi $sp, $sp, 4jr $ra好吧,据我所知。我是在正确执行此操作还是我完全失去了它? 最佳答案 分解然后实施v,k和j作为我们假定的寄存器进入。您需要构建地址v +(k k = k << 2;k = k + vj = j << 2;j = j + vtemp0 = load(k)temp1 = load(j)store(k) = temp1store(j) = temp0并且您应该能够将其转换为asm,可以重新安排一些说明并使其仍然有效。编辑,我会让你弄清楚,但我没有作弊并先编译。但是发现gcc产生了相同的基本指令序列。两个班次,两个加两个负载,然后两个存储。关于c - 汇编的C代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38964003/
10-14 04:10