嗨,我试图将一点存储到临时文件中。登记。我这样做正确吗?当我在做的时候,我想看看有多少个 1 是十进制数(0-16)的二进制形式,我这样做对吗?这是重要的代码块,其余的工作正常(只是输出,什么不是)
# for (i = 0; i <= 16; i++)
li $s0, 0 # i = 0
li $s3, 0 #constant zero
li $s4, 0 #i-2=0
bgt $s0, 16, bottom
top:
# calculate n from i
# Your part starts here
sb $t1, ($s0) #store LSB from number i in t1
sltu $t7,$s3,$t1 # check if t1 is a 1, if it is set t7 = 1
add $s1 ,$s3,$t1 # add 1 to n
ble $s4, 7, bloop # loop through rest of bits
bloop:
srl $t7, $s0, 1 # move bits in i right one, bringing in a zero from the left
sltu $t6, $s3, $t7 # check if t7 is a 1, if it is set t6 to 1
add $s1, $t6, $s1 # add increment n up 1
bgt $s4, 7, continue # break out of loop
continue: