# `ext`

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

**Sign-extend**

Category: Arithmetic

Sign-extends a data register’s low byte to word or its low word to long.

Sizes .w .l, .w by default

Used in: [Bytes, words and longs](https://asm-editor.specy.app/learn/courses/m68k/introduction/bytes-words-and-longs.md) (M68K assembly), [trap #15 and its tasks](https://asm-editor.specy.app/learn/courses/m68k/talking-to-the-outside-world/trap-15-and-its-tasks.md) (M68K assembly), [Flappy ASM](https://asm-editor.specy.app/learn/courses/m68k/examples/flappy-asm.md) (M68K assembly), [Numbers and sizes](https://asm-editor.specy.app/learn/courses/assembly-basics/introduction/numbers-and-sizes.md) (Assembly basics)

## Flags

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

## Forms

- `ext Dn`

## Operands

- [`Dn`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/direct.md): A data register, `d0` to `d7`.

## Description

`ext.w`, the default, copies the byte’s sign bit into bits 8 through 15 and leaves the upper word unchanged. `ext.l` copies the word’s sign bit into bits 16 through 31. The newly filled bits are 1 for a negative input and 0 for a nonnegative input.

## Example

```m68k
* --- Byte to word: sign-extends byte in low word ---
move.l #$0000007F, d0
ext.w d0 ; d0 = $0000007F (positive, no change)

move.l #$000000FF, d1
ext.w d1 ; d1 = $0000FFFF (-1 sign-extended)

* --- Word to long: sign-extends word ---
move.l #$00008000, d2
ext.l d2 ; d2 = $FFFF8000
```
