mips 程序无法识别 mips/mflo/sw
我想编写一个将十进制转换为二进制的程序。为此我将使用一个数组。请查看下面注释的行,并告诉我为什么它可能不起作用,因为 spim 模拟器说尝试执行非指令
.text
.globl __start
__start:
la $a0,prompt
li $v0,4
syscall
li $v0,5
syscall
move $t1,$v0
li $t0,0
la $t2,bin
#add $t2,$t2,124
lop:
div $t1,$t1,2
mflo $v0
sw $v0,($t2) #right here
add $t2,$t2,4
add $t0,$t0,1
ble $t0,32,lop
j dnn
ads:
la $a0,spc
li $v0,4
syscall
j back
dnn:
la $t0,bin
li $t3,1
la $a0,pr2
li $v0,4
syscall
add $t0,$t0,124
lp2:
lw $t1,($t0)
sub $t0,$t0,4
add $t3,$t3,1
move $a0,$t1
li $v0,5
syscall
div $t4,$t3,4
mflo $t4
ble $t4,0,ads
back:
ble $t3,33,lp2
li $v0,10
syscall
.data
prompt: .asciiz "Enter decimal: "
spc: .asciiz " "
pr2: .asciiz "\nbinary value:\n"
bin: .space 128
编辑:我做了一些更改,就像现在所有的“add”都是“addi”,而“.align 2”紧随其后。数据 同样在 SPIM 模拟器(PCSpim)中我注意到一些有趣的事情:
[0x00400020] 0x3c011001 lui $1, 4097 [bin] ; 15: la $t2,bin
[0x00400024] 0x342a0022 ori $10, $1, 34 [bin]
[0x00400028] 0x34010002 ori $1, $0, 2 ; 17: div $t1,$t1,2
[0x0040002c] 0x0121001a div $9, $1
[0x00400030] 0x00004812 mflo $9
[0x00400034] 0x00001012 mflo $2 ; 18: mflo $v0
[0x00400038] 0xad420000 sw $2, 0($10) ; 19: sw $v0,($t2)
为什么 mflo 做了两次?
I wanted to write a program that converts a decimal in to binary. For this I would use an array. Please look at the line commented below and tell me why it might not work because the spim simulator says attempting to execute non-instruction
.text
.globl __start
__start:
la $a0,prompt
li $v0,4
syscall
li $v0,5
syscall
move $t1,$v0
li $t0,0
la $t2,bin
#add $t2,$t2,124
lop:
div $t1,$t1,2
mflo $v0
sw $v0,($t2) #right here
add $t2,$t2,4
add $t0,$t0,1
ble $t0,32,lop
j dnn
ads:
la $a0,spc
li $v0,4
syscall
j back
dnn:
la $t0,bin
li $t3,1
la $a0,pr2
li $v0,4
syscall
add $t0,$t0,124
lp2:
lw $t1,($t0)
sub $t0,$t0,4
add $t3,$t3,1
move $a0,$t1
li $v0,5
syscall
div $t4,$t3,4
mflo $t4
ble $t4,0,ads
back:
ble $t3,33,lp2
li $v0,10
syscall
.data
prompt: .asciiz "Enter decimal: "
spc: .asciiz " "
pr2: .asciiz "\nbinary value:\n"
bin: .space 128
EDIT: I made some changes, like now all the 'add's are 'addi's and '.align 2' comes after .data
also in The spim simulator (PCSpim) I noticed something interesting:
[0x00400020] 0x3c011001 lui $1, 4097 [bin] ; 15: la $t2,bin
[0x00400024] 0x342a0022 ori $10, $1, 34 [bin]
[0x00400028] 0x34010002 ori $1, $0, 2 ; 17: div $t1,$t1,2
[0x0040002c] 0x0121001a div $9, $1
[0x00400030] 0x00004812 mflo $9
[0x00400034] 0x00001012 mflo $2 ; 18: mflo $v0
[0x00400038] 0xad420000 sw $2, 0($10) ; 19: sw $v0,($t2)
why is mflo done twice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mflo
执行了两次,因为DIV
伪指令这样做并且你之后就明确地这样做了。你可以这样做:
mflo
is done twice because theDIV
pseudo instruction does it and you're doing it explicitly right after.You can just do: