Section 02 Part 06 – Homework Results 02

 

 “When I was growing up, my parents told me, ‘Finish your dinner.  People in China and India are starving.’ I tell my daughters, ‘Finish your homework. People in India and China are starving for your job.” ~Thomas Friedman

 

 

 

Introduction

 

In the previous part, I gave you a list of instructions for you to test your knowledge.  In this part, we’ll go through each instruction to show you the answer to see if you got it right.

 

 

 

Results

 

          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.

 

          move.w    #$0010,d0

 

The word 0010 is moved into d0, d0 now contains 00000010.

 

          move.w    d0,$00000040

 

A word from d0 is copied into memory at offset 00000040.  0010 is copied, the 00 is copied to memory at 00000040, and the 10 is copied to memory at 00000041.

 

          move.w    d0,d1

 

A word from d0 is copied over to d1.  “0010” is copied over, and d1 now contains 00000010.

 

          add.w     d1,d1

 

A word of d1 is added to d1 (adding to itself).  0010 + 0010 = 0020, d1 now contains 00000020.

 

          add.w     d0,d1

 

A word of d0 is added to d1.  0020 + 0010 = 0030, d1 now contains 00000030

 

          sub.w     $00000040,d1

 

A word from memory at 00000040, is copied and subtracted from d1.  The 00 and 10 from memory 00000040 and 00000041 is loaded, 0010 is subtracted from d1.  0030 – 0010 = 0020, d1 now contains 00000020.

 

          swap      d1

 

d1 is swapped, d1 now contains 00200000.

 

          move.w    d0,d1

 

A word from d0 is copied over to d1.  “0010” is copied over, and d1 now contains 00200010.

 

          movea.l   #$00000040,a4

 

The offset 00000040 is loaded into address register a4.

 

          add.w     (a4),d1

 

The word in memory at the offset inside a4 is added to d1.  The offset inside a4 is 00000040, so the 00 and 10 from memory 00000040 and 00000041 is loaded, 0010 is added to d1.  0010 + 0010 = 0020, d1 now contains 00200020.

 

          move.w    d1,(a4)

 

A word from d1 is copied into memory at the offset inside a4.  0020 is copied, the 00 is copied to memory at 00000040, and the 20 is copied to memory at 00000041.

 

          exg.l     d1,d0

 

d1 and d0 are exchanged.  d1 now contains 00000010, and d0 now contains 00200020.

 

          swap      d0

 

d0 is swapped, d0 now contains 00200020 (the same as before because both the upper and lower word are the same).

 

          clr.w     d0

 

A word of d0 is cleared.  Now d0 contains 00200000.

 

And there is your final result, d0 contains 00200000 afterwards.  If you didn’t get that right, don’t worry, as long as you understand what the instructions individually do, then it shouldn’t be a problem.

 

 

 

Previous Part

Main Page

Next Part