# `pack`

[M68K Documentation](https://asm-editor.specy.app/documentation/m68k.md) › [Instructions](https://asm-editor.specy.app/documentation/m68k/instruction.md)

Web page: https://asm-editor.specy.app/documentation/m68k/instruction/pack

**Pack BCD** · 68020

Category: Arithmetic

Packs two decimal digits from a word into one packed decimal byte.

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

## Flags

| Flag | Effect |
| --- | --- |
| X | not changed |
| N | not changed |
| Z | not changed |
| V | not changed |
| C | not changed |

## Forms

- `pack Dn, Dn, #imm`
- `pack -(An), -(An), #imm`

## Operands

- [`Dn`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/direct.md): A data register, `d0` to `d7`.
- [`#imm`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/immediate.md): A 16-bit adjustment added to the source word before packing, for example `#0`.
- [`-(An)`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/indirect-post-pre-increment.md): The source address decreases by 2 before reading two bytes. The destination address decreases by 1 before writing one byte, or by 2 if it is `sp`.

## Description

Each digit occupies the low four bits of a byte in the source word. The ASCII text `'42'`, for example, is `$3432`; packing it with adjustment `#0` gives `$42`.

`pack` adds the 16-bit adjustment to the source word, then copies bits 11–8 to the high digit and bits 3–0 to the low digit. With data-register operands, it reads the source’s low word and writes the destination’s low byte, leaving the destination’s upper bits unchanged. With two predecrement operands, it decreases the source address by 2 and reads those two bytes, then decreases the destination address by 1 and writes one byte. If the byte destination is `sp`, it decreases by 2 to keep the stack pointer even. This processes a string from its end. The flags are unchanged.

[unpk](https://asm-editor.specy.app/documentation/m68k/instruction/unpk.md) reverses the packing, and [abcd](https://asm-editor.specy.app/documentation/m68k/instruction/abcd.md) adds packed decimal values.

## Example

```m68k
opt p=68020
* --- The text "42" as one byte of packed decimal ---
move.w #'42', d0 ; the two ASCII digits: $3432
pack d0, d1, #0 ; d1 = 66, which is $42: a 4 and a 2

* --- A string of digits, packed from its end ---
lea digits+4, a0 ; just past the four digits
lea packed+2, a1 ; just past the two bytes they pack into
pack -(a0), -(a1), #0 ; "34" into $34
pack -(a0), -(a1), #0 ; "12" into $12
move.w packed, d2 ; d2 = 4660, which is $1234
bra END

digits:
    dc.b '1234'
packed:
    ds.b 2

END:
```
