In: Computer Science
HCS12 Assembly Language:
1. Write a program to convert a decimal number stored at memory location $1010 into a binary number. Store the result in memory location $2000
Step(1). Basic idea of Decimal to binary conversion
Let consider Decimal number have five Digits
If Decimal Is = N1 N2 N3 N4 N5
(Where N1 is Most Significent Number)
Then Binary is = ((((N1x 10) + N2) x 10 + N3) x 10 + N4) x 10 + N5
Step(2). HCS12 program to convert a decimal number stored at memory location $1010 into a binary number. Store the result in memory location $2000
; processing N1
ldaa $1010 ; A = N1 (the most significant digit)
ldab #10 ; B = 10
mul ; operation (1) D = N1 x 10
std $2000 ; store the result in $2000
; processing N2
ldab $1011 ; B = N2
clra ; A = 0 so D = A:B = 00: N2
addd $2000 ;operation (2) d = [$2000]+D = (N1 x 10) + N2
; process N3
ldy #10 ; Y = 10\
emul ; Y:D = D x Y operation (3)
std $2000 ; d = ((N1 x 10) + N2) x 10
ldab $1012 ; B = N3
clra ; A = 0 so D = A:B = 00: N3
addd $2000 ; operation (4) d = ((N1 x 10) + N2) x 10 + N3
; process N4
ldy #10 ; Y = 10
emul ; Y:D = D x Y operation 5
std $2000 ; d = (((N1 x 10) + N2) x 10 + N3) x 10
ldab $1013 ; B = N3
clra ; A = 0 so D = A:B = 00: N4
addd $2000 ;operation (6) d = ((((N1 x 10) + N2) x 10 + N3) x 10) + N4
; process N5
ldy #10 ; Y = 10
emul ; Y:D = D x Y operation (7)
std $2000 ; d = (((((N1 x 10) + N2) x 10 + N3) x 10) + N4)x 10
ldab $1014 ; B = N5
clra ; A = 0 so D = A:B = 00: N5
addd $2000 ; operation (8) d = ((((((N1 x 10) + N2) x 10 + N3) x 10) + N4)x 10 ) + N5
I Hope it will Helpfull............