# `asd`

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

**Arithmetic shift**

Category: Shifts and rotates

Shifts the bits of the destination operand to the left or right.

## Flags

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

## Forms

- `asd <ea>, Dn` · Sizes .b .w .l, .w by default
  - Source: Dn, #imm
- `asd <ea>` · Size .w
  - Operand: (An), (An)+, -(An), d(An), d(An,Xn), abs (memory 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).
- [`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): An immediate shift count from `1` to `8`, for example `#3`.

## Description

Two forms: (1) `as<d> Dx/Im, Dn` shifts Dn by the count in Dx or immediate (1–8), any size. ASR fills the new high bits with copies of the sign bit, ASL fills the new low bits with zeros. Defaults to word. Note: ASL sets the overflow flag if the MSB changes during the shift, while ASR always clears it. (2) `as<d>.w (An)` shifts a memory word by 1; `.w` is the only size accepted and may be omitted.

## Example

```m68k
* --- ASR: arithmetic shift right (preserves sign) ---
move.w #$FF00, d0
asr.w #4, d0 ; d0 = $FFF0 (sign bit preserved)

move.w #$0F00, d1
asr.w #4, d1 ; d1 = $00F0 (positive, fills with 0)

* --- ASL: arithmetic shift left ---
move.w #$0001, d2
asl.w #4, d2 ; d2 = $0010

; ASL sets V if the MSB changes during the shift
move.w #$7000, d3
asl.w #1, d3 ; V flag set! MSB changed from 0 to 1

* --- Memory form: shifts word at (a0) left by 1 ---
lea $2000, a0 ; free memory: the program itself is at $1000
move.w #$0001, (a0)
asl (a0) ; (a0) = $0002
```
