私は開発中のM68kコンピュータ用の小さなOSを書いていますが、少し問題があります。私はそれを行うために、次のコードを書いたユーザーに進(31)16進値(たとえば$ 1F)を表示できるようにする必要がありますが、それはいくつかの問題があります。m68k十進法から十進法へ正しく動作しない
ConvertHexByteToDecimal:
move sr, -(sp) ; Back up status register to stack.
move #$2700, sr ; Disable interrupts.
move.b d2, -(sp) ; Back up d2 to the stack.
and.b #$0F, d2 ; Get rid of the high nybble
cmp.b #$9, d2 ; Is the low nybble in the range of 0-9?
bgt.s @convertHex ; If not, branch.
move.b (sp)+, d3 ; Restore the 10's place from the stack
and.b #$F0, d3 ; Get rid of the low nybble
add.b d3, d2 ; Add the 10's place.
bra.s @done ; If so, branch.
@convertHex:
sub.b #$A, d2 ; Subtract $A from the hexadecimal meeper.
move.b (sp)+, d3 ; Restore the 10's place from the stack
and.b #$F0, d3 ; Get rid of the low nybble
add.b #$10, d3 ; Add 1 to the 10's place.
add.b d3, d2 ; Add the 10's place to the number.
@done:
move.b d2, d1 ; Copy to output register.
move (sp)+, sr ; Restore status register.
rts ; Return to sub.
コードを最高$ Fまでの値でうまく動作します。たとえば、$ Bを入力すると11が出力されます。ただし、$ Fを過ぎると破損し始めます。私が$ 10を入力すると、出力は10になります。 $ xFの後には常に折り返します。
これを行う理由は誰にも分かりますか?
実際に10進数に変換しようとしません。元の値が10..15 mod 16の範囲にある場合は6を加算します。何も出力せず、レジスタに変更した値を返します。なぜあなたはこれが実際に何か役に立つことを期待していますか? –