mips - 使用 MIPS 计算单词数组中的元素数
问题描述
我正在尝试对 MIPS 进行编码以计算大于 x 且小于 y 的单词数组中的元素数,但代码似乎没有正确分支,我不断得到“count = 9”,即在这个案例,我列表中的元素数量。
.text
.globl __start
__start: # execution starts here */
la $a0, ans # load str "count ="
li $v0, 4
syscall
la $t0,nums # load array into address
li $t1,0 # setting counter to 0
addi $s0, $zero, 50 # adding constant of 50
addi $s1, $zero, 100 #adding constant of 100
lw $t5,count # loading word "9"
again : lw $t4 ($t0) # load first element of array into t4
bgt $t4,$s0,passif50 #comparing if first element is greater than 50
passif50 : blt $t4,$s1,passif100 #comparing if first element is less than 100
passif100 : add $t1, $t1,1 #incrementing counter by 1
add $t0, $t0,4 #increment current array element pointer
sub $t5,$t5,1 #deincrement "count" word by 1
beqz $t5,done #when "count" word is equal to 0, exit loop
done : move $a0,$t1
li $v0,1
syscall # print the count
li $v0, 10
syscall # end program
.data
nums: .word 55,68,2,60,2000,51,99,1,67
count: .word 9
ans: .asciiz "count = "
endl: .asciiz "\n"
解决方案
推荐阅读
- react-native - 到达 ListFooterComponent 末尾时调用 React Native FlatList onEndReached
- ms-office - 将列中的单元格值填充到 Excel Office.js 中另一列中的空白单元格
- javascript - 将我的 JQuery 函数转换为 vanilla js - 多个 forEach 的问题?
- python - 如何从 Python 访问在 EMR 集群中创建的 Hive
- python - 使用 Exchangelib 加快获取电子邮件的速度
- certificate - 在 andorid tv 上安装 CRT 证书文件
- arduino - 失败:Arduino 草图上传到 Wemos Lolin D32——超时或数据包头无效
- gwt - GWT Bootstrap3 上下文菜单
- android - 在 Android 中以编程方式使用渐变着色图标
- unity3d - Unity 检测 ui 画布上的封闭白色表面