unpk

Unpack BCD 68020

Unpacks a byte of packed decimal into two bytes, one digit in each, and adds an adjustment, such as the one that makes them ASCII digits.

68020 only: select opt p=68020 before any code or data

XNZVC –––––
  • Changes no flag

Forms

  • unpk , ,
  • unpk , ,

Operands

Dn
A data register, d0 to d7. More
#imm
A 16-bit adjustment added after unpacking, for example #$3030 to produce ASCII digits. More
-(An)
The source address decreases by 1 before reading one byte, or by 2 if it is sp. The destination address decreases by 2 before writing two bytes. More

unpk d0, d1, #$3030 converts $42 to $3432, the ASCII text '42'.

With data-register operands, it reads the source’s low byte and writes the destination’s low word, leaving the upper word unchanged. With two predecrement operands, it decreases the source address by 1 and reads one byte (by 2 when the source is sp), then decreases the destination address by 2 and writes two bytes. The flags are unchanged. pack performs the reverse conversion.

opt p=68020
* --- Print a byte of packed decimal as two digits ---
move.b #$42, d0 ; 42 in packed decimal
unpk d0, d1, #$3030 ; d1 = 13362, which is $3432: the text "42"
lea text, a1
move.w d1, (a1)
move.b #14, d0
trap #15 ; prints "42"
bra END

text:
    dc.b 0, 0, 0, 0 ; the two digits, and the 0 that ends the text

END: