私は助けが必要です。このコードは MARS で作成しました。ユーザーから整数を受け取り、それを HEX に変換することになっています。私は何時間もそれを調べてきましたが、私が見る限り、うまくいくはずです。これは機能していない唯一の部分であるため、プログラムのループ部分と出力部分のみを含めました。誰かがコードが間違っている場所を指摘できますか? ありがとうございました。
PSビットごとのANDを台無しにしていると思います。これを使用して下位ビットをマスクしましたが、何らかの理由で、ANDではなくADDのように見えます。:-(
li $s1, 8 # Set up a loop counter
ループ:
rol $s0, $s0, 4 # Roll the bits left by four bits - wraps highest bits to lowest bits (where we need them!)
and $t0, $s0, 16 # Mask off low bits (logical AND with 000...01111)
slti $t1, $t0, 10 # Determine if the bits represent a number less than 10 (slti)
bne $t1, $zero, MakeLowDigit # If yes (if lower than 9), go make a low digit
MakeHighDigit:
subi $t0, $t0, 10 # Subtract 10 from low bits
addi $t0, $t0, 64 # Add them to the code for 'A' (65), becomes a..f
j DigitOut
MakeLowDigit:
addi $t0, $t0, 47 # Combine it with ASCII code for '0', becomes 0..9
桁アウト:
move $a0, $t0 # Output the ASCII character
li $v0, 11
syscall
subi $s1, $s1, 1 # Decrement loop counter
bne $s1, $zero, Loop # Keep looping if loop counter is not zero