Section 02 Part 05 The CLR Instruction


Three things are certain: Death, taxes, and lost data. Guess which has occurred. ~David Dixon, 1998, winning entry of the Haiku Error Messages 21st Challenge by Charlie Varon and Jim Rosenau, sponsored by






CLR CLeaR an operand


This instruction will clear the destination operand, setting it all to zero (0).






This instruction is straight forward:


clr.b d0



Byte (.b) was used, so the end byte is cleared (set to 00).


clr.w d0



Word (.w) was used, so the end word is cleared (set to 0000).


clr.l d0



Long-word (.l) was used, so the entire long-word of the register is cleared.


You can perform this instruction on memory locations (directly, or by using an address register), examples:


clr.w $00201000

clr.b $00201FFF

clr.w (a4)

clr.l $1C(a2)


However, you cannot use it directly on an address register:


clr.l a0


Of course, alternatives exist of clearing the address register, just an example here:


clr.l d0

move.l d0,a0






Below is a list of instructions, and Id like you to give a go at running through it, instruction by instruction:


move.w #$0010,d0

move.w d0,$00000040

move.w d0,d1

add.w d1,d1

add.w d0,d1

sub.w $00000040,d1

swap d1

move.w d0,d1

movea.l #$00000040,a4

add.w (a4),d1

move.w d1,(a4)

exg.l d1,d0

swap d0

clr.w d0


All of the data registers will start with 00000000 to begin with. After all of this is processed, what will d0 contain?


The answer and working out are on the next part, and just like before, be sure to give it a good go before moving on.




Previous Part

Main Page

Next Part