不能把这种C code到MIPS大会 [英] Cannot translate this C code to MIPS Assembly

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

问题描述

基本上我需要翻译这个C code( http://pastebin.com/7EupfQ5n )以MIPS汇编。我花了一条缝这个,但我有麻烦。

Basically I need to translate this C code (http://pastebin.com/7EupfQ5n) to MIPS assembly. I took a crack at this, but I am having troubles.

我到目前为止是这样的( http://pastebin.com/LpS6Mqr1 )。但是,当我在模拟器上运行code,它在一个无限循环,尽管我放入数组中的运行,我找不到它是这样做。我会认为它引用在同时,如果语句不正确的方式排列,但我不知道如何或为何。

What I have so far is this (http://pastebin.com/LpS6Mqr1). But when I run the code in a simulator, it runs in an infinite loop despite what I put into the array, and I cannot find where it is doing that. I would assume that it is referencing the array in an incorrect way in the while and if statements, but I'm not sure how or why.

如果有人可以帮助,那将是非常美联社preciated。

If anyone can help, that would be very appreciated.

此外,有没有办法有适用于Mac OSX一C到MIPS的编译器(译者?)?我安装GCC但-mips标志我产生一个错误。谢谢!

Also, is there a way to have a C to MIPS compiler (translator?) for Mac OSX? I have GCC installed but the -mips flag generates an error for me. Thanks!

推荐答案

要检查的最简单的方法是由编译器产生的输出来比较你组装code。

The easiest way to check is to compare your assembly code with the output generated by a compiler.

您不需要GCC做到这一点(并通过创建一个跨平台编译器所需的所有繁琐的步骤),如果您已经安装了铿锵你的机器上。然而不幸的是,这是安装在Mac上铿锵的版本不支持MIPS,所以你必须直接从LLVM的网站获得铿锵,或做一台Linux机器上。一旦你铛,只需运行

You do not need gcc to do this (and go through all the tedious steps required to create a cross-platform compiler) if you already have clang installed on your machine. Unfortunately, however, the version of clang that's installed on Mac doesn't support mips, so you'll have to either get clang directly from llvm's website, or do it on a linux machine. Once you get clang, simply run

铛-S -target MIPS -o mips.asm ./your_file.c

和使用 mips.asm 文件比较程序集code。

and compare your assembly code with the mips.asm file.

我已经包含了命令的输出这里

I've included output of the command here.

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

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