MIPS组件实现简单的for循环 [英] MIPS assembly for a simple for loop

查看:1095
本文介绍了MIPS组件实现简单的for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将此C代码转换为MIPS程序集. 这是C代码:

I need to translate this C code to MIPS assembly. Here is the C code:

int tmp = 0; 
for (int  j = 0; j < 15; ++j) 
     tmp = tmp * 2 + 3

这是我的MIPS汇编代码.翻译正确吗?如果您发现任何错误,我真的很想知道.

This is my MIPS assembly code. Is it a correct translation? If you see any mistakes I would really like to know.

# tmp = $v0
# j = $t0

.globl main

 main:
    li $v0,0

loop:
    bgt $t0,15,exit
    addi $t0,$t0,1
    mul $t1,$v0,2
    add $v0,$t1, 3
    j loop  

exit:

推荐答案

您的循环从0到14,因此您的bgt指令应为:bgt $t0,14,exit我认为.

Your loop goes from 0 to 14, so your bgt instruction should be: bgt $t0,14,exit I think.

.

这篇关于MIPS组件实现简单的for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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