lsr
Logical shift right
Shifts the bits of the destination operand to the right.
Used in
- Arithmetic, logic and bitsM68K assembly
- The screen, keyboard and mouse through trapsM68K assembly
- Even or odd, count the set bits, multiply by shiftingM68K assembly
- Binary searchM68K assembly
- The snake gameM68K assembly
- Flappy ASMM68K assembly
- Sampled soundM68K assembly
- Arithmetic, logic and bitsAssembly basics
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 allowedd(An,Xn)ord(PC,Xn)mode also permits the corresponding 68020 indexed and memory indirect forms. See 68020 addressing. More Dn- A data register,
d0tod7. More #imm- An immediate shift count from
1to8, 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 $2000, a0 ; free memory: the program itself is at $1000
move.w #$0010, (a0)
lsr (a0) ; (a0) = $0008