저는 개발중인 M68k 컴퓨터 용으로 작은 OS를 작성 중이며 조금 문제가 있습니다. 내가 그 일을 위해 다음 코드를 작성한 사용자에게 진수 (31)의 16 진수 값 (예를 들어 $ 1 층)을 표시 할 수 있어야하지만, 몇 가지 문제가 있습니다m68k 10 진수로 16 진수가 올바르게 작동하지 않습니다.
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을 추가합니다. 아무 것도 출력하지 않고 수정 된 값을 레지스터에 반환합니다. 왜 이것이 실제로 아무 것도 쓸만하지 않다고 생각하니? –