# `bfexts`

[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/bfexts

**Extract bit field signed** · 68020 · 68000 with opt bit

Category: Logic

Copies a bit field into a data register as a signed number, filling the bits above it with copies of its highest bit.

Select `opt p=68020`, or use `opt bit` with the 68000 or 68010, before any code or data

## Flags

| Flag | Effect |
| --- | --- |
| X | not changed |
| N | depends on the result |
| Z | depends on the result |
| V | always 0 |
| C | always 0 |

## Forms

- `bfexts <ea>{offset:width}, Dn`
  - Source: Dn, (An), d(An), d(An,Xn), abs, d(PC), d(PC,Xn)

## Operands

- [`<ea>`](https://asm-editor.specy.app/documentation/m68k/addressing-mode.md): An operand using one of the addressing modes listed for this form. The list determines whether it can be a register, memory or an immediate value. With `opt p=68020`, an allowed `d(An,Xn)` or `d(PC,Xn)` mode also permits the corresponding 68020 indexed and memory indirect forms. See [68020 addressing](https://asm-editor.specy.app/documentation/m68k/addressing-mode/68020.md).
- [`{offset:width}`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/bit-fields.md): A bit field: `width` bits that start `offset` bits below the operand’s most significant bit, written immediately after the operand. For example, `d0{24:8}` is the low byte of `d0`. A literal offset is 0 to 31 and a literal width is 1 to 32. Either may instead be a data register, as in `{d1:d2}`.
- [`Dn`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/direct.md): A data register, `d0` to `d7`.

## Description

The field is placed in the register’s low bits and sign-extended to long. For example, a 4-bit field containing `%1110` becomes `$FFFFFFFE` (-2).

N copies the field’s highest bit, and Z is set if the field is zero. V and C are cleared, and X is unchanged. [bfextu](https://asm-editor.specy.app/documentation/m68k/instruction/bfextu.md) fills the higher bits with zeros instead.

Write the field as `{offset:width}` immediately after its operand. It selects 1 to 32 bits, counted from bit 31 of a data register or bit 7 of the byte at the memory address. The offset and width may each be a constant or a data register. See [bit fields](https://asm-editor.specy.app/documentation/m68k/addressing-mode/bit-fields.md) for their ranges, register values and wrapping rules.

## Example

```m68k
opt p=68020
* --- Two signed numbers of 4 bits in one byte ---
lea pair, a0
bfexts (a0){0:4}, d0 ; %0011: d0 = 3
bfexts (a0){4:4}, d1 ; %1110, its top bit copied above it: d1 = -2
bfextu (a0){4:4}, d2 ; the same bits as an unsigned number: d2 = 14
bra END

pair:
    dc.b %00111110, 0

END:
```
