Addressing Mode Decoder

Purpose

To exercise complex addressing modes and to introduce bit manipulation:

Due dates

You must hand in answers to the questions at the beginning of your laboratory session on Thursday, September 18. This part of the assignment is worth 20 points.

You must be prepared to discuss your work at the beginning of your laboratory session on Tuesday, September 23, and to demonstrate your program to your TA during that period. This part of the assignment is worth 25 points.

Background

Section 4.5 of the text explains how machine language instructions are divided into an operation code that tells the computer what to do and some number of operand specifiers, providing the information needed to carry out that task. Section 4.5.1 gives an example of how single-address instructions are encoded. The operands of an instruction are specified by addressing modes. Addressing modes are introduced in Section 4.4 your text and then described in more detail in Section 5.3. It is important that you become familiar with these addressing modes, understanding what each does and how the information is conveyed by a combination of values in registers and in bits that form part of the instruction. As you gain more experience writing programs, these addressing modes will become second nature to you; at this point, however, you will probably need to refer to the material in Section 5.3 fairly often. Table 5.8 is a good summary of the addressing modes, while the figures in the remainder of Chapter 5 show how the addresses are computed in each case.

You are not expected to memorize any instruction encodings. While you need to understand the operations and addressing modes provided by the 68000, and be able to describe them in assembly language, the precise encodings are uninteresting. Nevertheless, instruction encodings provide a ready source of problems for programming exercises that concentrate your attention on bit manipulation and control flow. This exercise is intended to give you coding practice in a situation where the algorithm and the data being manipulated are relatively simple. It has the additional advantage of focusing your attention on addressing modes: what information they convey and how they are implemented.

Task

Implement an assembly language routine that decodes an MC68000 address mode specification and prints its meaning in the format given by the ``Assembler Syntax'' column from Table 5.8 of the text, except than ``n'' is replaced by the actual register number. Your routine must accept the first word of an instruction, examine the addressing mode defined by the low-order 6 bits, and use C-coded routines and global data to output a complete description of the addressing mode and its primary register. (You are not to consider any possible extension words.) Click here for the interface you must implement. Because we want to give you practice with several addressing modes, you are required to use at least immediate, register direct, and register indirect modes in your implementation.

Click here to get a zip file containing the source code for the driver and auxiliary routines, an assembly language skeleton, and an appropriate Makefile. Unpack that zip file just as you did in Homework #2.

First you must understand the interface specifications of the auxiliary routines and the strings you are given as global data. Then you must write a routine to decode the addressing mode and use those auxiliary routines and global data to output the description. We strongly suggest that you test and debug your routine on the HP simulator, but ultimately it must be run on the MB5.

The individual steps are expanded below.

Understand the environment

In this implementation, your routine will be called by a program written in C, and will itself call routines written in C. The interface specification for your routine defines how the C program will call you. File names.c contains interface specifications for dispStrVal and dispStr, the two routines you need to call, and the strings that are provided as global data.

Before starting to write your routine, you need to be certain about the role played by Table5_8, and how it is laid out in memory. (You will need this information to answer question 4 below.) Pay particular attention to the indexes of the strings in Table5_8, and how they relate to the encodings of addressing modes. If you are unsure of the data layout, you might find it helpful to compile names.c into assembly code. Use the following command:

mcc68k -g -S -Kf names.c

Making symbols accessible

File regmem.src contains directives that make the name of your routine available to the caller (XDEF) and that make the necessary symbols from the C-coded routines available to your code (XREF). You are responsible for adding all of the other assembly code to the file. (Review your solution to the last assignment for a typical routine structure.)

Symbols defined in an assembly language program are not normally visible outside the file containing that program. The XDEF directive makes a symbol visible to other files linked with the assembly file. In this case, regmem is a symbol with external linkage used in the driver program but not defined there. Note that an underscore has been prefixed, because the C compiler will prefix an underscore to its reference to the symbol. A description of the XDEF directive is found on page 6-78 of the on-line Assembler Manual. (Click here for a description of how to access the documentation if you don't already have an icon for it on your desktop.)

The XREF directive tells the assembler that certain symbols used by the routine are to be defined outside of this file. In fact, they are defined in names.c: Each of the symbols dispStrVal, dispStr, and Table5_8 has external linkage in its C compilation unit and is therefore known outside that compilation unit. When the C compiler translates a program, it prefixes an underscore to every symbol with external linkage.

Decoding the operand

The routine regmem must decode the last 6 bits of an instruction word as an operand that specifies either a register or a memory address. These bits contain Mode and Register fields. On the basis of these fields, regmem must select an appropriate string from Table5_8 and decide whether a register number must be output. It must then call either dispStrVal or dispStr to output the decoded addressing mode.

In order to separate the Mode and Register fields and obtain their values, you might want to use the logical instructions described in Section 8.1 of the text and the shift instructions described in Section 8.2. The EQU directive (Section 5.2.2, page 148) provides a convenient mechanism for defining symbols to represent constants, thus making your code easier to understand. You may also check the on-line Assembler Manual for a description of the EQU directive.

Calling external procedures

When your code calls a procedure, such as dispStrVal or dispStr, it needs to follow the C conventions for procedure invocation. These convention are described on pages 1-10 of Interlanguage Calling in Chapter 10 of the on-line C Manual.

Running the program

After you are convinced that your program works, run it on the MB5. (Review the procedure if necessary.)

Questions

  1. (6 points) Do exercise 4.5.3 on page 121 of the text.
  2. (6 points) Do exercise 5.3.5 on page 174 of the text.
  3. (2 points) Do exercise 5.9 on page 176 of the text. (In the set-up for the question, the end of the line of text above question 5.8 should read ($2100)=$50.)
  4. (6 points) Draw a diagram showing how the data defined by names.c is laid out in memory. Label the location denoted by Table5_8, and use arrows to indicate the locations addressed by any offsets stored in the data structure. Be certain that your diagram shows how many bytes are occupied by each value.

Demonstration

You must demonstrate your program to your TA on one of the machines in the Microlab.
Instructor Revision 1.40 (2007/08/27 00:15:43)