asr

Arithmetic shift right

Shifts the bits of the destination operand to the right.

Used in
XNZVC ●●●0●
  • ● set from the result
  • 0 always 0

Forms

Operands

<ea>
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. More
Dn
A data register, d0 to d7. More
#imm
An immediate shift count from 1 to 8, for example #3. More

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.

* --- 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