MIPS 到 C 的翻译 [英] MIPS to C Translation

查看:75
本文介绍了MIPS 到 C 的翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一些 MIPS 汇编指令翻译成 C 代码.我想我明白了,但这似乎违反直觉.有什么帮助吗?我们将变量 f、g、h、i、j 分别存储在寄存器 $s0、$s1、$s2、$s3 和 $s4 中.数组 A 和 B 的基数分别存储在 $s6 和 $s7 中.4 字节字.代码中的注释是我自己的.

I need to translate some MIPS assembly instructions to C code. I think I got it, but it seems counter-intuitive. Any help? We have variables f, g, h, i, j stored in registers $s0, $s1, $s2, $s3 and $s4 respectively. The base of arrays A and B are stored in $s6 and $s7 respectively. 4 byte words. Comments in the code are my own.

addi $t0, $s6, 4   # $t0 = A[1]
add $t1, $s6, $0   # $t1 = A[0]
sw $t1, 0($t0)     # $t0 = A[0]
lw $t0, 0($t0)     # $t0 = A[0]
add $s0, $t1, $t0  # f = A[0] + A[0]

我只是觉得我错了.如果我们从不使用它,为什么要先制作 $t0 A[1] 呢?

I just feel like I'm wrong. Why make $t0 A[1] first if we never use it?

推荐答案

sw $t1, 0($t0)     # $t0 = A[0]

你已经把这个从后到前了.这是一个商店,所以它使用:

You've got this back-to-front. It is a store, so it is used:

sw $t1, 0($t0)     # A[1] = $t1

这篇关于MIPS 到 C 的翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆