Code: Select all

```
;D0=binary number (0-9999)
;D2=binary number converted to four digit BCD
moveq #0,d2 ;Clear conversion register.
moveq #3,d7 ;Number of BCD digits-1.
loop2
divu #10,d0 ;D0:LOW = D0/10, D0:HIGH = D0%10
move.l d0,d1 ;Copy to split quotient and remainder
and.l #$FFFF,d0 ;D0:HIGH = 0
clr.w d1 ;D1:LOW = 0, D1:HIGH = 0..9
ror.l #4,d1 ;Align new digit to the end (div goes backward)
ror.w #4,d2 ;Make room to add digit to BCD number
add.w d1,d2 ;Add digit to binary number.
dbra d7,loop2
```

Code: Select all

```
;D0=binary number (0-9999)
;D2=binary number converted to four digit BCD
moveq #0,d2 ;Clear conversion register.
moveq #3,d7 ;Number of BCD digits-1.
loop3
divu #10,d0 ;D0:LOW = D0/10, D0:HIGH = D0%10
move.l d0,d1 ;Copy to split quotient and remainder
and.l #$FFFF,d0 ;D0:HIGH = 0
clr.w d1 ;D1:LOW = 0, D1:HIGH = 0..9
add.l d1,d2 ;Add digit to binary number.
ror.l #4,d2 ;Pull it back into 16-bit window
dbra d7,loop3
```

Sincerely,

Scorpion Illuminati