My goal is to display the solution of 2 numbers entered by the user in Hexadecimal. As of right now my code gets 2 numbers from the user, then returns the solution in decimal. What i think i should do is just to get my decimal solution and convert it into Hexadecimal after the numbers have been added together. If there is another plausible way please let me know. Thanks You.
org $8000
START movea.l #MSG1, A1
move.b #13,D0
trap #15
clr.w D2
JSR Loop
move.w d2, d4
movea.l #msg2, a1
move.b #13,D0
trap #15
clr.w d2
jsr loop
movea.l #msg3, A1
move.b #13,D0
trap #15
add.w d4, d2
JSR DISP
MOVE.B #9,D0
TRAP #15
LOOP move.b #5,D0
trap #15
cmp.b #$0D, D1
BEQ BREAK
and.b #$0F, d1
mulu #10, d2
add.w d1, d2
jmp loop
Break rts
DISP clr.b d3
DISDIV divu #10, D2
move.b #16, d5
ror.l d5, d2
or.b #$30, d2
move.b d2, -(A7)
addq #1, d3
clr.w d2
ror.l d5, d2
bne DISDIV
DISDIG move.b (a7)+, D1
move.b #6,D0
trap #15 ; char out
subq.b #1, D3
bne DISDIG
rts
org $8100
MSG1 DC.B 'Please enter a two digit number ', 0
MSG2 DC.B 'Please enter another two digit number ', 0
MSG3 DC.B 'The sum of the two 2 digit numbers you entered is ', 0
end start
I am using the EASY68k Assembler.
You need to change both the input and output code.
The input code ANDs the character with $0f
, which works when the character is 0-9 but not when the character is a-f. You'll need to test the character and treat it differently for the a-f case. Then you'll need to multiply the prior result by 16 instead of 10.
You have the opposite problem on output. Changing the divu
from 10 to 16 gets you halfway there, but where you add $30 to convert to ASCII 0
-9
you'll need to test the value and add $41 instead if it's between 10 and 15.