Section 04 Part 10 – Homework Results 04 “A good essay is 10% inspiration, 15% perspiration, and 75% desperation.” ~Unknown author

Introduction

I left with you a list using a load of instructions explained in this section, so you could try and work out what d0 contained afterwards.  So let’s see how well you did.

Results

 move.w    #\$0010,d0           mulu.w    #\$0003,d0           neg.w     d0           ext.l     d0           asr.l     #\$01,d0           ror.w     #\$01,d0           ext.l     d0           divu.w    #\$0002,d0

d0 starts with 00000000.

 move.w    #\$0010,d0

d0 now contains 00000010.

 mulu.w    #\$0003,d0

 0010 x 0003 = 00000030

d0 now contains 00000030.

 neg.w     d0

0030 is changed to -0030 (FFD0).  Now d0 contains 0000FFD0.

 ext.l     d0

The word FFD0 inside d0 is extended to long-word, currently d0 contains:

 0000 0000 0000 0000 1111 1111 1101 0000

The MSB of FFD0 is 1 (set), so d0 is extended to:

 1111 1111 1111 1111 1111 1111 1101 0000

Now d0 contains FFFFFFD0.

 asr.l     #\$01,d0

d0 contains FFFFFFD0 in binary:

 1111 1111 1111 1111 1111 1111 1101 0000

Arithmetically shifting right by 1 will give us:

 > 1111 1111 1111 1111 1111 1111 1110 1000 >

Now d0 contains FFFFFFE8.

 ror.w     #\$01,d0

The word FFE8 of d0 is now rotated right by 01 bit:

 > 0111 1111 1111 0100 v ^ < < < < < < < < < < <

Now d0 contains FFFF7FF4.

 ext.l     d0

The word 7FF4 inside d0 is extended to long-word, currently d0 contains:

 1111 1111 1111 1111 0111 1111 1111 0100

The MSB of 7FF4 is 0 (clear), so d0 is extended to:

 0000 0000 0000 0000 0111 1111 1111 0100

Now d0 contains 00007FF4.

 divu.w    #\$0002,d0

 00007FF4 ÷ 0002 = 3FFA r0000

Now d0 contains 00003FFA.

And there is your answer, d0 contains 00003FFA afterwards.  Please remember, I don’t expect you to work these all out in your head, if you’d prefer to use a calculator, that’s fine.  The purpose of these homework(s) is to ensure that you understand how the instructions work individually.  They’re not here to test your mathematics.