Assembly 我的mips代码中返回X的倍数的错误,其中X是1、2、4、8、16等等
我一直收到一个异常错误我的代码怎么了?谢谢 错误很少Assembly 我的mips代码中返回X的倍数的错误,其中X是1、2、4、8、16等等,assembly,mips,Assembly,Mips,我一直收到一个异常错误我的代码怎么了?谢谢 错误很少 您使用la$t1,count加载计数地址,但不加载 它的价值(6) 您试图在用户输入读数返回之前保存它 在退出时,您尝试加载符号,但该符号不存在 另外,你的算法也没有多大意义,但你不太清楚你的目标是什么,所以我无法修正它 包含修复程序的代码: # arrayCount.asm .data arrayA: .word 11, 3, 4, 5, 6, 7 count: .word 6 .text main:
la$t1,count
加载计数地址,但不加载
它的价值(6)# arrayCount.asm
.data
arrayA: .word 11, 3, 4, 5, 6, 7
count: .word 6
.text
main:
# code to setup the variable mappings
la $t0, arrayA
la $t1, count
# code for reading in the user value X
li $v0, 5
move $t3, $v0
syscall
# code for counting multiples of X in arrayA
addi $t4, $zero, 0 #number
start:
beq $t1, $zero, exit
lw $t6, 0($t0)
and $t5, $t3, $t6
addi, $t1, $t1, -1
la $t0, 4($t0)
beq $t5, $zero, update
j start
update:
addi $t4, $t4, 1
j start
# code for printing result
exit:
li $v0, 1
la $a0, number
syscall
# code for terminating program
li $v0, 10
syscall
您忘记发布您收到的完整错误消息,并指出它所指的代码行。您将希望
sll
创建2的幂。包括错误消息以进行更改。
# arrayCount.asm
.data
arrayA: .word 11, 3, 4, 5, 6, 7
count: .word 6
.text
main:
# code to setup the variable mappings
la $t0, arrayA
lw $t1, count # fix #1
# code for reading in the user value X
li $v0, 5
syscall # fix #2
move $t3, $v0
# code for counting multiples of X in arrayA
addi $t4, $zero, 0 #number
start:
beq $t1, $zero, exit
lw $t6, 0($t0)
and $t5, $t3, $t6
addi, $t1, $t1, -1
la $t0, 4($t0)
beq $t5, $zero, update
j start
update:
addi $t4, $t4, 1
j start
# code for printing result
exit:
li $v0, 1
move $a0, $t4 # fix #3
syscall
# code for terminating program
li $v0, 10
syscall