MIPS assembly for a simple for loop

删除回忆录丶 提交于 2019-12-03 08:22:12

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

.

You don't set j ($t0) to zero before the loop.

Raul Batalha
.data
mensage: asciiz "Text Test"
newline: asciiz "\n"
.text

# tmp = $v0
# j = $t0

main:
    li $t0,0
    li $t1,0
    li $t3,0
loop:
    bgt $t0,15,exit
    addi $t0,$t0,1
    j loop
    mul $t1,$t1,2
    add $t3,$t1,3  
exit:

li $v0,0
syscall

I also don't know what MIPS simulator you're running, but I know some of them don't constants and they demand you assign those to registers. So like bgt Rsrc1, Src2, label, normally if you put an integer in src2 the computer will translate that but I know for some you'll get an error doing add $v0, $t1, 3 as it won't translate add into addi. Same with mul. I know my SPIM simulator doesn't allow it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!