こんにちは、一時的に少し保存しようとしています。登録。私はこれを正しくやっていますか?そして、私はそれに取り組んでいますが、10進数(0〜16)の2進数形式で1がいくつあるかを確認しようとしていますが、これは正しいですか?ここに重要なコードのチャンクがあり、残りは正常に動作します(出力だけでなく、そうでないものもあります)
# 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: