# `bset`

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

**Test a bit and set**

Category: Logic

Sets the bit in the second operand numbered by the first operand, setting Z to the inverse of its old value.

Sizes .b .l

Used in: [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/m68k/think-in-assembly/arithmetic-logic-and-bits.md) (M68K assembly)

## Flags

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

## Forms

- `bset <ea>, <ea>`
  - Source: Dn, #imm
  - Destination: Dn, (An), (An)+, -(An), d(An), d(An,Xn), abs (data alterable)

## 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).
- [`#imm`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/immediate.md): An immediate value. As the first operand, it selects a bit: `0` to `31` for a data register, or `0` to `7` for memory.

## Example

```m68k
* --- Sets the specified bit ---
move.l #%0000, d0
bset #2, d0 ; bit 2 was 0 (Z set), now 1. d0 = %0100

move.l #%0100, d1
bset #2, d1 ; bit 2 was already 1 (Z clear), no change
```
