Section 01 Part 06 – Addressing & Program Flow

 

If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.”  ~One of Murphy's Laws of Technology

 

 

 

Introduction

 

There are a few important things about addressing, which need to be covered before learning other instructions.  We’ll also take a look at the standard flow and direction of programming assembly code.

 

 

 

Odd addressing

 

By now, you will of course have seen examples of moving data in and out of memory, for example:

 

          move.w    $00000046,d0

 

What you don’t know however, is that you cannot move “word” or “long-word” sized data in and out of memory, if the address is an odd number:

 

          move.w    $00000047,d0

 

Because 00000047 is an odd number (an odd address/offset), the 68k has trouble working with it, and will crash with an “address error”.

 

You can only access data on odd addresses using “byte”:

 

          move.b    $00000047,d0

 

The above example is OK, because only a byte is loaded from that odd address.

 

The same applies to “address registers”, if you have an odd address inside an address register, and then attempt to load a “word” or “long-word” in or out of memory from it, the 68k will crash:

 

          movea.l   #$00000047,a0

          move.w    (a0),d0

 

This applies to ANY instruction, not just the MOVE instruction.  As long as you make sure that only bytes are move to and from odd addresses, then you’ll do fine.

 

 

 

Program Flow

 

You’ve probably already worked this one out by now, but I digress.  When programming one instruction after another, the direction is always downwards:

 

          move.b    #$20,d0

          move.b    d0,d1

          move.w    d2,d0

 

So, always starting at the top:

 

  1. First:        move.b    #$20,d0
  2. Then:         move.b    d0,d1
  3. And Finally:  move.w    d2,d0

 

Always heading down, each instruction is dealt with, one by one.

 

There are instructions available that will change the flow for a brief moment, but we’ll be coming to those at a later part.

 

 

 

Homework

 

This is a chance for you to test what you’ve learnt so far.  Below is a list of instructions which will move numbers to and from places:

 

          move.w    #$0123,d0

          move.b    d0,d1

          move.w    d1,d2

          move.l    #$FFFF0000,d3

          move.w    d0,d3

          move.l    d3,d0

          move.w    d2,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, be sure to give it a good go before moving on.

 

 

 

Previous Part

Main Page

Next Part