lsd

Logical shift

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

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

Forms

Operands

<ea>
An operand using one of the instruction’s supported addressing modes, such as d0, (a0)+ or 4(a1). It may name a register, memory or an immediate value. 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) ls<d> Dx/Im, Dn shifts Dn by the count in Dx or immediate (1–8), any size. New bits are filled with 0s. Defaults to word. (2) ls<d>.w (An) shifts a memory word by 1; .w is the only size accepted and may be omitted.

* --- LSR: logical shift right (fills with 0) ---
move.w #$FF00, d0
lsr.w #4, d0 ; d0 = $0FF0

* --- LSL: logical shift left (fills with 0) ---
move.w #$000F, d1
lsl.w #4, d1 ; d1 = $00F0

* --- Compare ASR vs LSR on negative value ---
move.w #$FF00, d2
asr.w #4, d2 ; d2 = $FFF0 (sign extended)
move.w #$FF00, d3
lsr.w #4, d3 ; d3 = $0FF0 (zero filled)

* --- Memory form: shifts word at (a0) right by 1 ---
lea $1000, a0
move.w #$0010, (a0)
lsr (a0) ; (a0) = $0008