Hong Kong Technical College (Tsing Yi)

Department of Electrical and Communications Engineering EE270 Digital Systems and Microprocessors

Name  Course, Group  Date

Workshop 0: Lab primer: MC68000 assembly language This lab primer is not to be handed in. You need to bring this to every lab class, or you will find it hard to do your lab work. There is only one copy available for each person. If you forget to bring it with you to the lab, we may not have another to give to you.

Contents

1 Introduction W0-3

2 I/O ports and the 68230 parallel interface/timer chip W0-3 2.1 The interface card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-4 2.2 The 68230 parallel interface/timer chip . . . . . . . . . . . . . . . . . W0-4 2.3 Register addresses in the 68230 PI/T on the Flight-68k . . . . . . . . W0-5 2.4 How the interface card is connected to the parallel chip . . . . . . . . W0-5

3 The keypad W0-7

3.1 Scanning the keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-7

3.1.1 The method . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-8 3.2 Debouncing the keys . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-9 3.3 How to detect if any key has been pressed . . . . . . . . . . . . . . . W0-10

4 68000 Assembly language W0-11 4.1 labels, opcodes, operands and comments . . . . . . . . . . . . . . . . W0-11 4.2 Comments in programs . . . . . . . . . . . . . . . . . . . . . . . . . . W0-11 4.3 Integer numbers in programs . . . . . . . . . . . . . . . . . . . . . . . W0-12 4.4 Registers in the 68000 . . . . . . . . . . . . . . . . . . . . . . . . . . W0-12

4.4.1 Flags in the status registers . . . . . . . . . . . . . . . . . . . W0-12

ver 1.5, 13 February 1995  Ref. EE/27/LA/21/95

Hong Kong Technical College (Tsing Yi)  EE270 Digital Systems and Microprocessors

4.5 Addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-13 4.5.1 Direct addressing mode . . . . . . . . . . . . . . . . . . . . . . W0-14 4.5.2 Immediate addressing mode . . . . . . . . . . . . . . . . . . . W0-14 4.5.3 Address register indirect with displacement addressing mode . W0-14 4.5.4 Address register indirect with index addressing mode . . . . . W0-15

4.6 Tables in MC68000 assembly language . . . . . . . . . . . . . . . . . W0-16 4.7 Loops: the dbf instruction . . . . . . . . . . . . . . . . . . . . . . . . W0-16 4.8 The cmp instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-17 4.9 What if you find an instruction you do not know? . . . . . . . . . . . W0-17

5 Subroutines W0-17

6 The stack W0-19

6.1 The push operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-19

6.1.1 An example of a push operation . . . . . . . . . . . . . . . . . W0-19 6.2 The pop operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-20

6.2.1 An example of a pop operation . . . . . . . . . . . . . . . . . W0-20

7 Preserving registers: transparency W0-21

8 Subroutine calls, parameters and return values W0-21

9 Subroutine calls and the stack W0-22 9.1 The bsr and jsr instructions . . . . . . . . . . . . . . . . . . . . . . W0-22 9.2 The rts instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-22 9.3 The subroutine must leave the stack as it found it . . . . . . . . . . . W0-23

10 An example showing a subroutine call W0-23

11 The include file, �������� and the macros W0-24 11.1 The Init macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-25 11.2 The Delay macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-25 11.3 The WriteSs macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-25 11.4 The Transl macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-25 11.5 The ShowNum macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-26

CONTENTS

ver 1.5, 13 February 1995

W0-2

Ref. EE/27/LA/21/95

11.6 The WNKeyPr macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-26

11.7 The WKeyPr macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-26

11.8 Equates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-26

12 The ���� instruction and monitor routines W0-27

13 The general procedure for editing, assembling, downloading and running an assembly language program W0-27

13.1 Editing the program . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-28

13.2 Assembling the program . . . . . . . . . . . . . . . . . . . . . . . . . W0-28

13.3 Downloading your program . . . . . . . . . . . . . . . . . . . . . . . . W0-29

13.4 Running the program . . . . . . . . . . . . . . . . . . . . . . . . . . . W0-29

1 Introduction

This section introduces some new topics to you.

This lab primer introduces many new concepts that you will apply in the laboratory. Your lab sheets will refer to this primer. You need to read the parts referred to by your lab sheets before you come into the lab. I suggest that you use a highlighter as you read, highlighting the important points in different colours so that you can find them easily when you are in the lab.

2 I/O ports and the 68230 parallel interface/timer chip

An I/O port is a special memory location in an input or output hardware device. An I/O port is a connection between a computer and the outside world. For instance, the keyboard, printer and mouse on a desktop computer all are connected to the PC through I/O ports.

When we read from an input port, we cause input from something outside the computer. Data is transferred from outside to inside the computer through the input port. An input is a special sort of read operation.

When we write to an output port, we cause data to be transferred from the computer to hardware that is outside the computer. An output is a special sort of write operation.

In a memory-mapped I/O computer, such as the Flight-68k in our labs, we use ordinary data movement instructions to do input and output, such as move or clr. An input or output port has an ordinary address, like memory. The only difference is that an address decoder selects an I/O chip such as the 68230 PI/T instead of a memory chip. The I/O

ver 1.5, 13 February 1995

W0-3

Ref. EE/27/LA/21/95

chip is connected to external hardware so that it may perform input and output. The special memory locations in the 68230 are called registers—they are all listed in table 2 on page W0-6. You may read some more about them in the Flight-68k manual, in chapter 11

Here are some examples of input and output operations, as in our lab work:

        move.b  #$f,leds(a6)    OUTPUT: Turn on the four LEDs on the right.
        move.b  switch(a6),d0   INPUT from the dip switches into D0.
        clr.b   keys(a6)        OUTPUT zero to the keypad (port A)

The first operation outputs the bit pattern 0000 1111 to port B, which is connected to the LEDs. This output operation is performed by writing to the port B data register, which is at address $800013_{16}—see tables 1 on page W0-5 and 2 on page W0-6.

The second operation inputs from port C, which is connected to the dip switches. This input operation is performed by reading the port C data register, which is at address $800019_{16}—see tables 1 on page W0-5 and 2 on page W0-6.

The third operation sends the data value 0 out of the port A data register, which is at the address 800011_{16}.

The names leds, switch and keys are named constants, defined in the file flight.i. See section 11.8 on page W0-26 for more about these names..

2.1 The interface card

On the 68000 microprocessor I/O interface card^{1} there are four devices, two for input and two for output. The input devices are a bank of eight dip switches and a telephone keypad. The output devices are a set of eight LEDs (Light Emitting Diodes) and a seven segment display.

2.2 The 68230 parallel interface/timer chip

All these devices are connected to the 68230 parallel interface and timer (PI/T) chip via a 40 wire ribbon cable.

The PI/T has three ports. On this chip, a port is a set of eight pins. Each of these pins can be each individually set up as an input or as an output. This is more flexible than the Intel 8255A parallel chip, in which the pins in one port cannot be assigned as inputs and outputs in any order.

The ports are called port A, port B and port C. Some of the pins in port C can be used also as inputs and outputs for the timer, and some others as control signals for transfers to and from ports A and B. We use port C as an input port since it is connected to the dip switches.

W0-4

Ref. EE/27/LA/21/95

1I will call the 68000 microprocessor I/O interface card the interface card from here on.

2.1 The interface card ver 1.5, 13 February 1995

register  address offset name
Port A data register 800011_{16} 10_{16} keys
Port C data register 800019_{16} 18_{16} switches
Port B data register 800013_{16} 12_{16} sevSeg or leds

Table 1: The port addresses in the 68230 PI/T and their names

[figure: 1; 2; 3; JP1; 1; 2; 3; JP1; LEDs selected; Seven segment; display selected]

Figure 1: The two settings for the jumper on the interface board

The 68230 PI/T has a base address of $800 001. The port A data register has offset $10 from the base address of the PI/T, the port B data register has offset $12 from the base address, while port C has offset $18 from the base address. This means that port A is at address $800 001 + $10 = $800 011, while the port B data register is at address $800 001 + $12 = $800 013, while the port C data register is at address $800 001 + $18 = $800 019. See section 11.8 on page W0-26 for how these constants are defined. See table 1 for a list of the port addresses.

2.3 Register addresses in the 68230 PI/T on the Flight-68k

A 68230 PI/T has 23 separate registers. These occupy 64 memory locations. Individual bits in these registers can be set to control the behaviour of the IC. Three of them are the data registers used to communicate with the keyboard, dip-switches and LEDs in our lab work. Table 2 on page W0-6 gives the addresses of the registers in the 68230 on the Flight-68k.

2.4 How the interface card is connected to the parallel chip

The keypad is connected to port A while the LEDs and seven segment display are both connected to port B. The LEDs and seven segment display are selected by jumper; please see figure 1. When the jumper is in the upper position across pins 1 and 2, the LEDs are selected. When the jumper is across pins 2 and 3, the seven segment display is selected. The dip switches are connected to port C.

When you read from the port C data register, you read an 8-bit number with one bit for each of the 8 switches in the dip switch. When you write to the port B data register, the bottom eight bits cause the corresponding LED to turn on and off, or cause the corresponding segment on the seven-segment display to turn on and off. In both cases, a bit value of ‘1’ means “on”, a ‘0’ means “off”.

2.3 Register addresses in the 68230 PI/T on the Flight-68k

ver 1.5, 13 February 1995

W0-5

Ref. EE/27/LA/21/95

Hong Kong Technical College (Tsing Yi)  EE270 Digital Systems and Microprocessors
register  address offset  name
Port general control register  800001_{16} 0
Port service request register  800003_{16} 2
Port A data direction register  800005_{16} 4
Port B data direction register  800007_{16} 6
Port C data direction register  800009_{16} 8
Port interrupt vector register  80000B_{16} A_{16}
Port A control register  80000D_{16} C_{16}
Port B control register  80000F_{16} E_{16}
Port A data register 800011_{16} 10_{16} keys
Port B data register  800013_{16} 12_{16} sevSeg or leds
Port A alternate register  800015_{16} 14_{16}
Port B alternate register  800017_{16} 16_{16}
Port C data register 800019_{16} 18_{16} switches
Port status register  80001B_{16} 1A_{16}
Timer control register  800021_{16} 20_{16}
Timer interrupt vector register 800023_{16} 22_{16}
Counter preload register, high  800027_{16} 26_{16}
Counter preload register, middle 800029_{16} 28_{16}
Counter preload register, low  80002B_{16} 2A_{16}
Count register, high  80002F_{16} 2E_{16}
Count register, middle  800031_{16} 30_{16}
Count register, low  800033_{16} 32_{16}
Timer status register  800035_{16} 34_{16}

Table 2: The addresses of registers in the 68230 PI/T on the Flight-68k

2.4 How the interface card is connected to the parallel chip

ver 1.5, 13 February 1995

W0-6

Ref. EE/27/LA/21/95

[figure: 1; 2; 3; 4; 5; 6; 7; 8; 9; ∗; 0; #; PA_{0}; PA_{1}; PA_{2}; PA_{3}; PA_{4}; PA_{5}; PA_{6}; PI/T; Telephone keypad; V_{CC}; PA_{7}; Not connected; O/P; O/P; O/P; I/P; I/P; I/P; I/P; I/P]

Figure 2: The connection of the keypad to the 68230 parallel interface/timer chip

3 The keypad

On the interface board, the keypad is connected to port A of the 68230 parallel interface/ timer IC.

The keypad is connected rather like figure 2. There is a key in the twelve positions where the vertical wires are shown crossing the horizontal ones. Each key connects the crossing wires when pressed. The columns are set up as outputs while the rows are set up as inputs. When no key is pressed, the row inputs are high.

3.1 Scanning the keypad

There are twelve keys on the keypad but we only have eight pins in one port. If we connected the key switches directly to twelve port pins, we could read the keys directly. But this will not work with a larger keypad or keyboard. Also port pins are too precious to waste—if possible, we would prefer to save them for another purpose.

If we have fewer port pins available, it is still possible to read the keypad by scanning it. To scan a 3 × 4 keypad, we use 3 + 4 port pins. We can use n + m port pins to scan a n × m keypad^{2}.

W0-7

Ref. EE/27/LA/21/95

2The method shown here is not the only way to scan a keypad—it is possible to scan \frac{1}{2}n(n − 1) keys with n port pins. For instance, it is possible to read 28 keys with 8 port pins—if you are interested, ask Nicholas Urbanik.

ver 1.5, 13 February 1995

3.1.1 The method

The idea is that we output a ‘1’ to two of the column outputs to the keypad while outputting a ‘0’ to each column in turn. After the left-most column is set low, we can read each row in turn. Say the key ‘4’ on the keypad has been pressed (see figure 2 on page W0-7). If we read the rows (i.e., port inputs PA_{3} to PA_{6}), then bits PA_{3}, PA_{5} and PA_{6} are all ‘1’s, but PA_{4} is a zero, because the key has connected the line PA_{4} to PA_{0} on which we have output a ‘0’. The resistance between PA_{0} and ground is much lower than the value of the resistor between PA_{4} and V_{CC}, so PA_{4} will have a voltage close to zero volts. Let’s look at the steps in scanning the keypad, from a high level point of view.

• For each column:

∘ drive that column low and the others high.

∘ Read the rows.

∘ For each row

– If that row bit is ‘0’, then have found the key—exit.

– increment the key index

• If no key was found, then set key index to noKey

• The key index now has a number from 0 to 11 if a key was pressed, or a value of noKey if no key was pressed.

Let’s now look at the steps in greater detail. It may help to read the program in section ?? on page ?? in lab 4, Scanning a keypad in MC68000 assembly language.

step 1 Start by initialising the key index number that indicates the current key, the column counter and the column pattern that we will output to the keypad columns

step 2 for each column, starting from PA_{0}, drive that column low while driving the other columns high

step 3 Read the pattern of bits from the rows, i.e., PA_{3} to PA_{6}. To do this, we read the 8 bits from the keypad port into a register, then rotate the 8 bits three times, so that the bit from the top row is in bit position 0, i.e., in the LSB (least significant bit) position.

step 4 for each row:

step 4a Rotate the LSB into the carry flag in the CPU status register. Look up how the ror and rol instructions work in the Flight-68k manual, your text book or any 68000 reference book.

step 4b check whether the carry flag is low. If it is, then the current key has been pressed.

step 4c if the current key has not been pressed, then increment the key index number and try the next row—go to step 4a.

3.1 Scanning the keypad

ver 1.5, 13 February 1995

W0-8

Ref. EE/27/LA/21/95

step 5 Roll the bit pattern for the columns one position left so that we are ready to drive the next column low and the other columns high.

step 6 If we have read all the columns, then no key was pressed, so put a special value into the key index register to show that no key has been pressed.

step 7 We now have the key number. Use this as an index to look up the value of the key in a lookup table.

This list of steps is called a task list. We can also express the algorithm in pseudocode. Pseudocode is a mixture of English (or you can use Cantonese if you like!) and some programming language. Here I have combined English with Pascal, since you have studied Pascal:

Algorithm ReadKey:
key = 0, col = 2, columnPattern = $FE
while col <> -1 do
   row = 3
   keypad = columnPattern
   rowPattern = keypad
   roll port A bit 3 into rightmost bit position of rowPattern
   while row <> -1 do
      roll LSB of rowPattern into CPU carry flag
      if carry flag is clear goto found
      key := key + 1
      row := row - 1
   roll columnPattern left one position
   col := col - 1
key := noKey
found:

I hope that these two ways of showing the algorithm will help you to understand the subroutine ReadKey, first introduced in your lab work in section ?? on page ?? in lab 4.

3.2 Debouncing the keys

However, there is more to it than this. We need to deal with a problem called key bounce. When any switch opens or closes, it does not do so at only one moment. A closing switch will bounce open again for a very short time, close again, bounce apart again, and so on. This lasts about 10 milliseconds, depending on the type of switch. We need to be able to tell when a key has been pressed once and is bouncing or if it has been pressed more than once.

Small amounts of noise can also be interpreted as keystrokes when there are none.

There are many solutions to this problem, some using hardware such as a flip-flop or Schmidt trigger, others using software delay loops. We will take the software approach.

3.2 Debouncing the keys

ver 1.5, 13 February 1995

W0-9

Ref. EE/27/LA/21/95

If a key has been pressed, we can wait a while and see if it is still pressed some ten or twenty milliseconds later. If it is still seen as pressed, we shall say that this is a genuine keystroke.

We can use the Delay macro to create a delay of 20 milliseconds:

        Delay   20      Delay 20 milliseconds.

Please read section 11.2 on page W0-25 for more about the Delay macro.

3.3 How to detect if any key has been pressed

To see how to scan a keypad we look here at the first part of the problem: detecting a keystroke. How can we do this?

One simple way is to output a low to all the columns (i.e., to bits 0, 1 and 2 of the keypad port, port A).

How do we write the pattern which has bits 0, 1 and 2 low? This is 0. To achieve this step, we can write:

        clr.b  keys(a6)     output 0 to keypad columns

Remember, to write to a port register, we put it as the destination operand, i.e., on the left side of the move instruction.

We can then read the keypad port. If any of the row bits (i.e., bits 3 to 6) are low, then a key has probably been pressed.

How can we do this? We can first input from the keypad into a register:

        move.b  keys(a6),d1     Register D1 contains the column bits

Now how can we find out if any of the rows are low? Well, first we need to clear our copy of the bits that are not in the rows, i.e., that are not bit 3, 4, 5 or 6. We use the and instruction to clear these bits.

We can write:

        andi.b  #$78,d1         Clear all the bits that are not row bits

Finally, we can compare this value read from the rows with $78. We can tell if a key has been pressed by seeing if these values are the same or different.

You will use this algorithm in your experimental work in section ?? on page ??, in lab 4.

What does it mean if the value is ���? Write here what we

can say about the number of keys pressed if the value read from the rows is equal to $78.

3.3 How to detect if any key has been pressed

ver 1.5, 13 February 1995

W0-10

Ref. EE/27/LA/21/95

4 68000 Assembly language

Here we look at some topics of assembly language relevant to the work you will do in your laboratory work.

4.1 labels, opcodes, operands and comments

A line in a 68000 assembly language program is divided into four parts: labels, opcodes, operands and comments. One or more of these may not be present. The format is:

⟨label⟩  ⟨opcode⟩  ⟨operands⟩  ⟨comments⟩
↑  ↑  ↑  ↑
No space or tab At least one space or tab  At least one space or tab  At least one space or tab

Optional  Required  May be required; depends on opcode  Optional

The assembler divides a line into these fields by considering spaces to separate the fields. For that reason, there must be no space between two operands, otherwise the assembler will consider the second operand to be a comment, and will give a syntax error message complaining that one operand is missing.

Many opcodes (and operands too) can have a suffix, which may be one of .B, .W or .L. These are shown in the following table.

Suffix Means: number of bytes number of bits
.B  byte  1  8
.W  word  2  16
.L  long word  4  32

4.2 Comments in programs

In the 68000 assembly language, comments can be written in two ways. A whole line comment begins at the left side of the screen with a symbol ‘*’.

Comments can also begin in the fourth field as mentioned in the previous section.

A comment is written for the human reader of a program. A comment has absolutely no effect on what the assembler sees; comments are ignored by the assembler.

You do not need to type the comments from these lab sheets into the computer. They are there to help you only.

ver 1.5, 13 February 1995

W0-11

Ref. EE/27/LA/21/95

When you write bigger programs of your own, then you should write comments, especially at the beginning of each subroutine explaining what the subroutine does. This saves a lot of time when you or someone else wants to change the program a year later.

4.3 Integer numbers in programs

Integer numbers can be expressed in decimal (the default), hexadecimal, octal or binary. There is a choice of suffixes and prefixes to show which representation is being used.

type  format  examples
decimal  ⟨number⟩, &⟨number⟩  297, &297
hexadecimal  $⟨number⟩, ⟨number⟩H       $FF, 0FFH
octal  @⟨number⟩, ⟨number⟩O, ⟨number⟩Q  @457, 457O, 457Q
binary  %⟨number⟩, ⟨number⟩B       %11011011, 11011011B

Notice that if you use H, the first digit must be 0–9, otherwise the assembler will think the value is a label.

4.4 Registers in the 68000

Inside the CPU there are eight temporary storage places that can each hold a 32-bit number. These are called the data registers. They are called D0, D1, D2, …, D7. There are also eight temporary storage locations to hold addresses inside the CPU. These are called the address registers. They are called A0, A1, A2, …, A7. A7 is special purpose and is called the stack pointer. The others can be used to hold any address. Note that we are using A6 to hold the base address of the 68230 parallel chip, so it is better not to change that either.

There are three other special registers. There is the program counter, labelled PC. The program counter always holds the address of the next instruction to be executed.

See section 6 on page W0-19 for more about the stack pointer register, A7, and the stack.

The next section discusses the status register.

4.4.1 Flags in the status registers

There is also a status register which has a number of flags. A flag is a single bit that can have the value 1 or 0. The flags we are interested in here in this lab are those in the lowest four bits. They each have a single letter name: X = extended flag, N = negative flag, Z = zero flag, V = overflow flag and C = carry flag. These five flags are also sometimes called the condition codes.

4.3 Integer numbers in programs

ver 1.5, 13 February 1995

W0-12

Ref. EE/27/LA/21/95

These five flags are set or cleared as the result of many instructions. See the Flight-68k manual or your text book to see what effect each instruction has on the flags. This table shows the five condition code flags:

name letter bit #  when set
carry  C  0  The current instruction had a carry out of MSB (most

significant bit), or if an unsigned subtraction, a borrow. This is equivalent to: the result of the current instruction, considered as an unsigned operation, did not fit in the destination.

overflow  V  1  The result of the current instruction, considered as a signed

operation, did not fit in the destination. With addition, overflow can only happen when adding two numbers of the same sign. In this case, answer is of the opposite sign if and only if there was overflow.

zero  Z  2  The result of the last instruction was zero
negative  N  3  The result of the last operation was negative
extend  X  4  Used in arithmetic with data bigger than 32 bits to take

carries from one long word to the next.

Overflow from addition may only happen when two numbers of the same sign are added together. It will never happen when two numbers of opposite sign are added together. You can tell if there is overflow yourself, even without looking at the V flag in the 68000. If you add two positive numbers and the result is negative, then you have overflow. If you add two negative numbers and the result is positive, then you have overflow.

Overflow is only of interest you consider the numbers you are adding to be signed numbers. It indicates that the destination for the instruction was too small to hold the result of a signed operation.

Carry is more interesting when you are doing unsigned arithmetic—you can completely ignore it when you are doing signed arithmetic. For unsigned arithmetic, the carry flag indicates that the destination was too small for the result of an unsigned operation.

With subtraction, we have ⟨dest⟩ = ⟨dest⟩ − ⟨src⟩. The carry flag will be set if the source is greater than the destination, considering both the source and destination as unsigned numbers.

4.5 Addressing modes

The MC68000 has a lot of addressing modes: there are 14, of which we use 4 here. In this section we look at these addressing modes and see some examples of their use.

An addressing mode is a way of specifying the effective address of an operand, either in a register or in memory. The effective address tells us where the operand is. There are many addressing modes because there are many different ways of storing data, and addressing modes are designed for accessing data that is stored using these different methods.

4.5 Addressing modes

ver 1.5, 13 February 1995

W0-13

Ref. EE/27/LA/21/95

Chapter 7 of the Flight-68k manual discusses addressing modes. Also see pages 39–48 of Antonakos, The 68000 microprocessor, the text book.

4.5.1 Direct addressing mode

The first lab used the direct addressing mode most of all. It is perhaps the simplest addressing mode: the assembly language instruction gives the address of the operand. An example is shown here:

        org     data
value   dc.w
        org     prog
        move    value,d0        value is accessed using direct addressing

See page 44 of the text, under “absolute short address” and “absolute long address.” See also the Flight-68k manual on page 7–9 under the same headings. Note that the assembler decides itself whether to use absolute long or absolute short direct addressing; there is no need to specify a “.L” or “.W”as shown in the manual.

4.5.2 Immediate addressing mode

The first lab also used the immediate addressing mode. The value to be loaded is included with the instruction. The mode is indicated with a # in front of the number:

        move    #1,d0           Put the actual value 1 into D0.

See page 7–12 of the Flight-68k manual, or page 47 of the text book for some more information.

4.5.3 Address register indirect with displacement addressing mode

The address register indirect with displacement mode is new to you. We use this mode to access the registers of the parallel chip. First, the address register A6 is loaded with the base address of the parallel chip. The offset of the register from the base address is then added to the base address to give the address of the actual register.

Here is an example:

        move    $18(a6),d0      Load data from address given by
*                               adding 18_{16} to the contents of A6.

Note that in your lab work, you will use the constants leds, switches and sevSeg with this addressing mode. These constants have been defined in the file flight.i.

Here is another example, using the name leds defined in the file flight.i:

4.5 Addressing modes

ver 1.5, 13 February 1995

W0-14

Ref. EE/27/LA/21/95

        move    d0,leds(a6)     Copy data from D0 to address given by
*                               adding leds to the contents of A6.

The value of leds is $12 — see section 11.8 on page W0-26 and section 2.2 on page W0-4. The Init macro loaded the base address of the parallel chip ($800 001) into A6. The effective address of “leds(a6)” is then $800 001 + $12 = $800 013, which is the address of the port B data register in the 68230 parallel chip.

See pages 7–7 and 7–8 of the Flight-68k manual, or pages 42–43 of the text book for some more information about this addressing mode.

4.5.4 Address register indirect with index addressing mode

The register indirect with index addressing mode may also be new to you. In lab 3 we use it for looking up a pattern in a table to copy to the seven segment display. See page 7–8, section 7.6.2.5 of the Flight-68k manual for more information.

Here is an example of its use:

        move    $18(a0,d1),d0

Here, the hexadecimal value $18 and the contents of D1 are added to the contents of the register A0 to give the memory address from which the data is moved.

How would we use such an addressing mode? An example is looking up a number in a table. Suppose we have a table of bytes, which we could declare as:

table   dc.b    1,2,4,8,$10,$20,$40,$80

Now we could load the address of this table, which is given by the label table, into the address register A0:

        movea.l #table,a0       Immediate addressing mode

Note that that suffix is an .L, not a 1! See section 4.1 on page W0-11. Now suppose we want the fourth entry in this table. We could put the value 3 into D1 and then use the instruction:

        move.b  0(a0,d1),d0     Load value 8 from table into D0

Why did we put 3 into D0 to access the fourth entry in the table? Suppose #table has the value $400500. This means that the first element of the table has the address $400500, the second has address $400501, the third $400502 and the fourth has address $400503. Now the way the addressing mode works is that the number 0 is added to what is in A0, $400500, and also to what is in D1, 3, to get the address $400503, which is the correct address. So to access the first item in the table, we would put 0 into D1, and to access the last of the eight items in the table, we would load 7 into D1.

In lab 4, we will use this addressing mode for the last program in section ??.

See page 7–8 and of the Flight-68k manual, or page 43 of the text book for some more information.

4.5 Addressing modes

ver 1.5, 13 February 1995

W0-15

Ref. EE/27/LA/21/95

4.6 Tables in MC68000 assembly language

As we use the word here, a table is a collection of numbers that are put one after the other in the computer’s memory. We use an index to access individual numbers in the table. Another word for such a table is array. If you have used Pascal or C, you may have seen an array before.

In MC68000 assembly language, an array is declared with the dc, declare constant data command, or with the ds, declare storage command. Here are examples of each:

        org     $400500         data starts at this address
pattn   dc.b    $ff,$7f,$3f,$1f,$f,7,3,1  An array of 8 patterns
values  ds.w    5               An array of 5 words, not initialised.

If there are initial values the entries in the table should have, then we use dc. If there are no special values the entries should be initialised to, or if the table is very big, we can use

ds.

We can access the entries in the table using the register indirect with index addressing mode. See section 4.5.4 on page W0-15.

4.7 Loops: the ��� instruction

Computers are good at doing repetitive jobs: the loop construction is ideal for implementing such repetitive work. We use two basic kinds of looping operations: conditional and unconditional.

An unconditional loop just keeps going forever—or at least, till we press the reset button or turn the computer off. We may implement such loops using the bra instruction (branch always. Every time we execute the bra instruction, the program counter register is loaded with the address given by the label. The program will then execute the instruction with that label. Your lab sheets have many examples of the bra instruction.

A conditional loop can be more clever. It can stop looping when a condition is met. We often use a cmp (compare) instruction to set the flags in the status register, then we use a b_{cc} instruction such as beq to check those flags. The b_{cc} instruction will choose whether to jump (or ‘branch’) depending on the value of the status flags. These flags are the Zero, Negative, Carry, oVerflow and eXtended flags. See section 4.4.1 on page W0-12 for more about the status flags.

Another useful kind of looping instruction is the db_{cc} family of instructions. A very useful member of this family is the dbf or Decrement and Branch while False instruction. The dbf instruction takes two operands: a data register, and a label. This instruction does the following:

• The value in the data register is decremented by 1.

• If the data register is not −1, then the program will branch to the label.

4.6 Tables in MC68000 assembly language

ver 1.5, 13 February 1995

W0-16

Ref. EE/27/LA/21/95

• If the data register = −1, then the program will execute the instruction following the dbf instruction.

The dbf instruction can be used as like a for loop in Pascal or C, with a fixed number of times through a loop. There is an example of the use of dbf in section ?? on page ?? in lab 4.

4.8 The ��� instruction

The cmp instruction works the same as the sub instruction, except that the result is thrown away.

The syntax of the cmp instruction is

cmp.s ⟨ea⟩,Dn

.s is one of .B, .W or .L

⟨ea⟩ is an effective address given by any addressing mode, specifying the source ⟨src⟩

and Dn is any data register, specifying the destination ⟨dest⟩.

The CPU does the subtraction ⟨dest⟩ − ⟨src⟩, throws the result away, but sets the flags in the status register. See section 4.4.1 on page W0-12 for more about the flags.

4.9 What if you find an instruction you do not know?

There are some other instructions introduced in your lab work that you may not have seen before. There are several places to look. The back of the text book (Antonakos, The 68000 microprocessor) has details of each 68000 instruction.

The Flight-68k manual explains each instruction in chapter 8.

There is some online help with the assembler: to use this, at a DOS prompt, type

asmhelp ⟨Enter⟩.

5 Subroutines

A subroutine is a specialised program module that may be called upon from anywhere else in the program outside of the normal sequence of execution. Most programs contain subroutines. Subroutines are often called functions or procedures, especially in higher level languages. We will talk more about functions later.

Figure 3 on page W0-18 shows how a subroutine fits into the normal flow of execution of a program. At point a there is a call to the subroutine. This causes the next instruction in the execution of the program to be at point x. At y—the end of the subroutine—there is a return instruction, which causes execution to continue at the next instruction after point a. Later, at point b, there is another call to the same subroutine, so again the

4.8 The ��� instruction

ver 1.5, 13 February 1995

W0-17

Ref. EE/27/LA/21/95

[figure: subroutine; main program sequence; a; b; x; y]

Figure 3: Executing a subroutine

processor executes instructions between x and y. But this time, execution returns to the instruction immediately after point b.

[figure: first subroutine; main program sequence; a; b; x; y; nested subroutine; c; u; v]

Figure 4: Executing nested subroutines

Subroutines can also call other subroutines—see figure 4. Here, the first subroutine is executed as in figure 3, but when execution reaches instruction c, a call is made to a nested subroutine. Execution then starts at instruction u, the first instruction in the nested subroutine. At the end of the nested subroutine, a return instruction is executed at v, which causes execution to continue at the instruction immediately after instruction c. When the first subroutine finishes, the return instruction at y will cause execution to continue at the correct location—the instruction immediately after a or b, depending on where the call was made from. You will see that in this particular example, the nested subroutine is executed twice, as is the first subroutine.

ver 1.5, 13 February 1995

W0-18

Ref. EE/27/LA/21/95

Notice that when the subroutine finishes, it must return to just after where it was called from. This is different from the way a normal branch instruction works. A special data structure is required to hold the address of the instruction immediately after the calling instruction.

6 The stack

We could hold the return address of the subroutine in a single fixed location, but this would not allow one subroutine to call another, since each call would overwrite the previous value.

A stack data structure is generally chosen to hold these return addresses. The stack is usually in RAM. As mentioned in lecture 6, the stack is a last in, first out (LIFO) structure. A stack has two operations:

push The push operation adds a data item to the stack.

pop The pop operation removes the most recent value pushed (that has not already been popped). Some texts call this a pull operation.

LIFO means that the value that is removed with a pop operation is the value that was most recently pushed onto the stack. The memory address that holds the last value that was pushed is called the top of the stack.

Each memory location, as we have discussed earlier, holds one byte and has a unique number called an address. A special register called the stack pointer—A7 in the 68000— holds the address of the top of the stack.

On some other microprocessors the stack pointer points to the location where the next data item will be pushed, but on both the 68000 and 8086 microprocessor families, the stack pointer points to the address of the last data item already pushed onto the stack.

6.1 The push operation

The push operation has two steps. When a data item is pushed onto the stack,

1. the stack pointer is decremented by the size of the data item (in bytes)

2. the data value is copied into the location whose address is now in the stack pointer register.

Note that you can only push and pop data values with an even number of bytes.

6.1.1 An example of a push operation

In the 68000, there are a few instructions to push data onto the stack. When using the move instruction, the push operation uses the address register indirect with predecrement

ver 1.5, 13 February 1995

W0-19

Ref. EE/27/LA/21/95

addressing mode. As an example, the assembly language instruction to push a 32-bit long word value from the D0 register onto the stack is:

        move.l  d0,-(a7)        ; Remember A7 is the stack pointer.

Many registers can be pushed at once with the movem instruction. This example shows the 32-bit long word values in the registers D1, D2, D3, D4 and A0 all being pushed onto the stack:

        movem.l d1-d4/a0,-(a7)   Push all five registers onto the stack.

Note here that the dash ‘-’ between two registers means a range of registers: d1-d4 means registers D1, D2, D3 and D4. To specify registers that are not part of a range, separate them with slashes, as shown above.

Some of the programs you use in the lab sessions use the movem instruction at the beginning and at the end. This is to make them transparent. See section 7 on page W0-21 for more about transparency.

6.2 The pop operation

The pop operation is the reverse of the push operation. When a value is popped from the stack:

1. the data value is copied from the top of the stack into another location, either a register or a memory location.

2. the stack pointer is incremented—by the size of the data item that was removed, in bytes—to point to the new top of stack.

6.2.1 An example of a pop operation

Several instructions in the 68000 pop data from the stack. When using the move instruction, the pop operation uses the address register indirect with postincrement addressing mode. As an example, the assembly language instruction to pop a 32-bit long word from the stack into the D0 register is:

        move.l  (a7)+,d0        ; Pop operation.

Suppose that before this instruction executes that A7 contains the value 4003F0_{16}. In this example, the “.l” means “long word”, (4 bytes) so the operation first copies 4 bytes from memory locations 4003F0_{16}, 4003F1_{16}, 4003F2_{16} and 4003F3_{16} into the 32-bit D0 register. Then the A7 register is incremented by 4 so that it finally has the value 4003F4_{16}.

Many registers can be popped at once with the movem instruction. This example shows 5 32-bit long word values being popped from the stack into registers D1, D2, D3, D4 and A0:

        movem.l (a7)+,d1-d4/a0   Pop all five registers from the stack.

6.2 The pop operation

ver 1.5, 13 February 1995

W0-20

Ref. EE/27/LA/21/95

7 Preserving registers: transparency

Very often we use registers to hold variables in programs. There are many advantages to this: registers are quickly accessible—they are already inside the CPU. A program that keeps its variables all in registers will run faster than if it keeps many variables in memory.

There is one problem here—there is a limited number of registers. The 68000 has more registers than many microprocessor, but we can still run out. We may need to program other microprocessors with fewer registers. We may want to use a register for more than one variable.

Another problem is local variables in subroutines. The problem is that one subroutine may need five registers, and may call other subroutines that also need a few registers. Suppose the second subroutine changes a register that the first subroutine was using?

A solution to all these problems is to make the subroutines “transparent”. We make a subroutine transparent by saving all the registers that it uses. Where do we save them? The system stack is a very convenient place. The subroutine can push all the registers it uses onto the stack as the very first action it does, then, at the very end, just before the rts instruction, it pops the the same registers in exactly the opposite order.

A convenient instruction to do this is the movem instruction, which will push or pop as many registers as you want, always taking care of doing these operations in the correct order. Please see the sections 6.1 and 6.2 on page W0-20 for more information about these operations.

All the subroutines used in lab 4 are as ‘transparent’ as possible. Most of the macros used in the lab also begin with push and end with pop operations.

8 Subroutine calls, parameters and return values

Sometimes a subroutine does not need any information to do its job; if Init were a subroutine, it would need no extra information—it would just initialise the parallel chip. However, some other subroutines do need to pass some information in or out to be useful. For example, the ReadKey subroutine in section ?? of lab 4 needs to let us know what the key was that it read. It does this by putting the key index into the D0 register. We say that it returns the key index in D0, or that the key index is its return value.

Similarly, the GetKey subroutine, also in section ?? on page ?? of lab 4, returns a key index in register D0.

Information may be passed to a macro or subroutine through registers. An example is the Transl macro, described in section 11.4 on page W0-25. Transl takes a key index in register D0 and returns a number, also in D0, that corresponds to the value on the top of the key.

ver 1.5, 13 February 1995

W0-21

Ref. EE/27/LA/21/95

9 Subroutine calls and the stack

When a subroutine call is executed, the processor saves the return address on the top of the stack. When the most recent subroutine call finishes, the last stored return address is retrieved from the top of the stack. In this way, subroutines that call other subroutines (nested subroutines, as in figure 4 on page W0-18) will also return to the correct location, since the first subroutine call will be the last one to return.

9.1 The ��� and ��� instructions

In the 68000, the call operation is implemented by either the bsr instruction or the jsr instruction.

Both do the same thing, except that bsr can only use relative addressing modes, whereas jsr can use many addressing modes. To see the difference, refer to the Flight-68k manual, chapter 8, or the text book. Here we are interested in what these instructions do with the stack.

Suppose a subroutine is called sub1. Then a call to this subroutine with either jsr sub1

or bsr sub1 will:

1. push the address of the instruction immediately following the call instruction onto the stack.

2. load the address of the first instruction in the subroutine into PC.

The first step saves the return address of the subroutine on the stack. Because the return address is a long word (4 bytes), the push operation will decrement the stack pointer by 4 before copying the return address to the stack. The second step causes execution of the instructions in the subroutine to begin.

9.2 The ��� instruction

Every subroutine must end with the rts (return from subroutine) instruction.

When the rts instruction executes, it simply pops the long word (32-bit) value from the top of the stack into PC (the program counter register). The effect is to cause program execution to continue from the instruction immediately after the instruction that called the subroutine.

That is,

1. the four bytes at the top of the stack are copied into the program counter

2. the stack pointer is incremented by 4

Hence, the rts instruction is simply a pop operation.

ver 1.5, 13 February 1995

W0-22

Ref. EE/27/LA/21/95

9.3 The subroutine must leave the stack as it found it

An important requirement is that when execution reaches the rts instruction, the stack must be exactly the same as it was immediately after the subroutine was called. If it is not, then something else will be popped into the PC, and the computer is likely to ‘hang’.

10 An example showing a subroutine call

[figure: 4003F0; A7; 4003F0; 4003EF; 4003EE; 4003ED; 4003EC; ⋮; ⋮; High memory addresses; Low memory addresses; 4003EC; A7; 4003F0; 4003EF; 4003EE; 4003ED; 4003EC; ⋮; ⋮; High memory addresses; Low memory addresses; lsb  16; 04; 40; msb  00; STACK; STACK; 400410; PC; 400450; PC; Before call to sub1; After call to sub1]

Figure 5: The stack before and after the call to subroutine sub1.

A subroutine sub1 at address 400450_{16} is called. The instruction

        jsr     sub1

is at location 400410_{16}. Figure 5 shows the arrangement of the stack before and after the call.

• Before the call, the stack pointer A7 is pointing to the top of the stack, which just happens to be at address 4003F0_{16}.

Here are the three steps performed by the CPU when it executes the call instruction:

• The stack pointer is decremented by four, since an address occupies 4 bytes

• The return address, 400416_{16} is copied from the program counter onto the top of the stack

• The address of the subroutine, 400450_{16} is copied into the program counter

9.3 The subroutine must leave the stack as it found it

ver 1.5, 13 February 1995

W0-23

Ref. EE/27/LA/21/95

• After the call, the value 400416_{16} is pushed onto the stack, since the jsr sub1 instruction at address 400410_{16} is 6 bytes long. 400416_{16} = 400410_{16} + 6. 400416_{16} is the address of the instruction immediately after the jsr instruction. The address of the top of the stack is always held in the stack pointer, A7.

• Because the program counter holds the address of the first instruction of the subroutine, the CPU executes instructions in the subroutine.

11 The include file, �������� and the macros

You will notice that the programs in labs 3 and 4 all have the line

        include flight.i

Also, the first instruction in each program is

        Init            Initialise the parallel chip

The first instruction opens a file, flight.i, which contains the definition of the names leds, sevSeg and switches. The file also contains the definition of several macros called

Init, Delay, WriteSs, Transl, ShowNum, WNKeyPr and WKeyPr. You may look at the file

flight.i if you like.

A macro is a sequence of instructions that has a name and that has a single idea or algorithm. A macro can be ‘called’ from anywhere in the program. A macro is rather like a subroutine. The difference from a subroutine is that each time you ‘call’ a macro, the instructions are inserted directly into that location by the assembler. If you call a macro ten times, the code for the macro will be inserted ten times in your program. On the other hand, if you call a subroutine ten times, the code for that subroutine will still only appear once in the program. A subroutine must finish with a rts instruction, while a macro does not.

A macro may take one or more parameters, such as the Delay macro, described in section 11.2 on page W0-25. The other macros here take no parameters, but some may use information provided in register D0, and some provide information in register D0.

These macros have been written so that they disturb the rest of your program as little as possible. They do this by pushing all registers that they use (except D0 in most cases, and A6) onto the stack, and then popping the registers back from the stack afterwards.

I have included these macros to make the lab work quicker for you to do.

To call a macro, simply type the name of the macro in the opcode field of your program, as shown in the programs in your lab sheet. It is necessary to type the same case as shown, as this assembler is case sensitive with the names of macros. Hence it is necessary to type Init and not init, WriteSs and not writess, and so on.

ver 1.5, 13 February 1995

W0-24

Ref. EE/27/LA/21/95

11.1 The ���� macro

The macro Init initialises the 68230 parallel chip, and also loads its base address into the A6 register for use with the address register indirect with displacement addressing mode—see p. 42–43 of Antonakos (the text book), or p. 7-7 and 7-8 of the Flight-68k user manual for more about this addressing mode. Init sets the port connected to the LEDs as outputs, the port connected to the switches as inputs, and also sets the keypad port up correctly, with port bits 0, 1 and 2 as outputs, and the other five bits as inputs.

The Init macro contains six instructions. If you single-step through your program, you need to step over these first six instructions.

11.2 The ����� macro

The Delay macro takes one parameter, as mentioned above. The parameter is a counting number, and is provided after the name Delay, like this:

        Delay   20      Delay 20 milliseconds.

Delay preserves all the registers it uses. In other words, all registers will have the same value before and after calling Delay.

Delay will simply keep the CPU busy counting until the number of milliseconds specified by the parameter has passed.

11.3 The ������� macro

The WriteSs macro (write to seven segment display) takes a number in register D0 and uses a lookup table to display the value on the seven segment display, as in the last lab session.

Only the four right-most bits are used; other bits in D0 are cleared.

All other registers are not affected.

11.4 The ������ macro

The Transl macro (translate from a key index to key value) is used to interpret the result of ReadKey. ReadKey gives a number in the range 0 to 11, with the following values:

Key index:  0 1 2 3 4 5 6 7 8 9 10 11
Value printed on the key: 1 4 7 ∗ 2 5 8 0 3 6 9 #

Here, the “Key index” is the index returned by ReadKey. The “Value printed on the key” is what you see when you look at the telephone keypad yourself.

11.1 The ���� macro

ver 1.5, 13 February 1995

W0-25

Ref. EE/27/LA/21/95

Transl uses a lookup table to take the key index as input (in D0) and provides the actual key value as output (also in D0). For ‘∗’ it returns $A, and for ‘#’ it returns $B, since the idea is to display the result on the seven segment display, which cannot display a ‘∗’ or a ‘#’.

11.5 The ������� macro

The ShowNum macro takes a value in register D0 and displays the value as a four-digit decimal number on the terminal screen. It does this by serial transfer, using monitor firmware routines, in the ROM on the Flight-68k board.

All other registers are preserved besides D0.

11.6 The ������� macro

The WNKeyPr macro simply waits till a key is not pressed on the keypad. All registers are preserved. It is very similar to the macro WKeyPr.

11.7 The ������ macro

The WKeyPr macro simply waits till a key is pressed on the keypad. All registers are preserved. It uses the algorithm described in section 3.1.1 on page W0-8. You will work with a program to use this algorithm in section ?? on page ?? in lab 4.

11.8 Equates

Equates give a particular constant value to a label. The values of leds, sevSeg and switches are set using equates. If you are familiar with Pascal, an equate is like a Pascal constant defined with const.

Here is an example of some equates, showing the values given to these names:

keys     equ     $10             Port A data register
switches equ     $18             Port C data register
sevSeg   equ     $12             Port B data register
leds     equ     $12             Port B data register

So keys has the value $10, leds and sevSeg both have the value $12, and the name switches has the value $10. These values are the offsets from the base address of the 68230 parallel chip. See section 2.2 on page W0-4 for more about the 68230 parallel interface/timer chip. Also, see page 11-2 of the Flight-68k manual for a list of all the registers in the PI/T and their addresses on the Flight-68k computer.

11.5 The ������� macro

ver 1.5, 13 February 1995

W0-26

Ref. EE/27/LA/21/95

12 The ���� instruction and monitor routines

Almost every program here ends with a pair of lines that look like this:

        trap    #11
        dc.w    0

The trap instruction is used here to call a monitor routine. The monitor is a collection of programs that are in the EPROM on the Flight-68k boards. These are mentioned briefly on page W0-29. The number on the line with the dc.w directive indicates which of these monitor programs you want to call. There are 28 of these routines, and they are listed on page 5–3 of the Flight-68k manual. Three of them are used for the ShowNum macro—see section 11.5 on page W0-26 for more about this macro.

Each program here terminates with a call to the renter routine, which terminates the program and enters the monitor routine that listens for your keystroke commands, such as when you type ⟨l⟩⟨t⟩ to begin a download, or ⟨g⟩⟨o⟩ to start a program running.

13 The general procedure for editing, assembling, downloading and running an assembly language program

Remember: for each program, you will always use the same five steps:

• edit ; • assemble ; • download  • run ; • observe

1. Before the PC is turned on, be sure that you have an interface card plugged into a Flight-68k microprocessor board, and that power is supplied to the microprocessor board and that the serial connection is made to the PC.

2. If you switch on the PC, from the MS-DOS Startup Menu, select option 3, “Standalone

     Workstation”

3. If you want to output to the seven segment display, set the jumper on the interface board to the seven-segment display position, as in figure 1 on page W0-5. If you are using the LEDs, set the jumper to the other position.

4. Change to the c:\68x directory by typing:

cd \68x ⟨Enter⟩

ver 1.5, 13 February 1995

W0-27

Ref. EE/27/LA/21/95

13.1 Editing the program

If your program uses any macros, please read about them in 11 on page W0-24. Note that you must type the macro names in the same case as shown in that section, or you will get an “illegal opcode” assembler error message.

Here I assume that the program you are working with is called ⟨program⟩.asm. Just put the name of your own program instead of ⟨program⟩.

We will use the same editor—Q-edit—as for the previous labs.

1. Edit a new program using Q-edit by typing

q ⟨program⟩.asm ⟨Enter⟩

2. Type in your program.

3. Save this program and exit Q-edit by typing

⟨Alt-x⟩

13.2 Assembling the program

If the name of your assembly language program is ⟨program⟩.asm then you can assemble it by:

1. At the C:\68X> prompt, type

xasm ⟨program⟩ ⟨Enter⟩

2. In response to the

Object file:  [⟨program⟩.BIN]

prompt, press the ⟨Enter⟩ key.

3. In response to the prompt for a list file, you can either

• press ⟨Enter⟩, in which case the listing file will be displayed on the screen, or

• type

⟨program⟩ ⟨Enter⟩

in which case a file ⟨program⟩.lst will be created containing the assembler listing output. You can examine this file with an editor if you like.

4. If the assembler reports 0 errors and 0 warnings then assembly was successful. Otherwise, write down the error messages. These show both the line number and the position in the line where the error was found. Edit the program again. The first error or warning is usually the best place to start. Examine that line and correct the error. Then assemble your program again until there are no errors or warnings.

13.1 Editing the program

ver 1.5, 13 February 1995

W0-28

Ref. EE/27/LA/21/95

13.3 Downloading your program

Downloading a program is sending the assembler output from the PC to the Flight-68k board by a serial transfer. I assume here that the output from the assembler was the file ⟨program⟩.bin. If you are working with a different filename, use that name instead of ⟨program⟩.

1. Start the serial communications program at 9600 bits per second. We run the program at a baud rate of 9600 bits per second by typing:

comm /b9600

This program is also called a terminal program, since the PC behaves as a terminal for the Flight-68k board.

2. Press the ⟨Enter⟩ key three times until an F> prompt appears.

If no F> prompt appears, press the RESET button on the Flight-68k board (not the one on the PC!) then press ⟨Enter⟩ three times. Call the lecturer or technician if you still get no F> prompt.

3. Type

⟨l⟩⟨t⟩

There are some programs in the Flight-68k EPROM. These programs are called the monitor programs. They are also called firmware because they remain after the power is turned off. The command ⟨l⟩⟨t⟩ is a command to the monitor firmware to be ready to receive a serial stream of characters from the PC. See also section 12 on page W0-27 for more information about the firmware.

4. When prompted with:

ENTER OFFSET (<CR> IF NONE) :

press the ⟨Enter⟩ key.

5. Now press the ⟨F2 ⟩ key, and when prompted, enter the name of the program:

⟨program⟩

This is a command to the terminal program to start sending characters from the file ⟨program⟩.bin down the serial cable.

6. The firmware will give a message LOAD COMPLETED indicating that the transfer was successful.

13.4 Running the program

1. Type

⟨g⟩⟨o⟩

13.3 Downloading your program

ver 1.5, 13 February 1995

W0-29

Ref. EE/27/LA/21/95

2. In response to the request for a starting address, type the number that is the address of the first instruction in your program. This is given by the org statement in your program that is put immediately before the first instruction. In labs 3 and 4, we will stay with 400400_{16}.

3. Observe what happens when the program runs.

4. To exit from the comm terminal program press the ⟨Esc⟩ key.

Reference: EE/27/LA/21/95

Compiled by  Issue  Date  Remark
Nick Urbanik  1  18-10-95  This is a reworking of workshop 3 for 2540 from 1994/95. Moved

the intro to the lab manual. Now for 2540, 2541, 2543.

13.4 Running the program

ver 1.5, 13 February 1995

W0-30

Ref. EE/27/LA/21/95