You must hand in the rationale for your decomposition, and your interface specifications, at the beginning of your laboratory session on Tuesday, October 14, and demonstrate your program to your TA during that period. This part of the assignment is worth 20 points.
There is no ``right'' answer to these questions; any strategy resulting in
a valid implementation is correct.
Different strategies will have different advantages and disadvantages, and
will be more or less complex to carry out.
You should discuss various decompositions before beginning the actual
coding, trying to see how you can compartmentalize the process to make
debugging easier.
You should also think about how best to use the simulator, monitor, and
MooseLoad to reduce the testing and debugging time.
A 2's-complement calculator
The behavior to be implemented is a simple, four-function calculator for
8-bit, 2's-complement numbers.
Its keyboard is the HP keyboard, and its display is the LEDs connected
to the MB5's digital output.
You are given a C-coded input routine to read from the HP's keyboard.
Click here for the interface specification.
Only the keys 0-9, a-f (upper and lower case), +, -, *, /, and = are recognized by the program. There are two 8-bit, 2's-complement registers called acc and buf. The content of either of these registers can be displayed, but the display is simply a ``snapshot'' of that register at a given time.
A state machine provides a way to model the behavior of the calculator program as a function of time: At any given instant, the machine is in a given state. It is then given an input, which causes it to perform some action and then go to some state. This cycle continues, with the machine accepting a sequence of inputs. Each input results in an action and a state transition. Some of the actions involve writing the value of either acc or buf to the MB5's digital output, others involve carrying out 2's-complement arithmetic on one or both of the registers.
The machine has five states:
| State | Inputs | ||
|---|---|---|---|
| digit | operator | equal | |
| init | shift / initd | -- / init | -- / init |
| initd | shift / initd | store,rator / oper | store / equal |
| oper | shift / operd | rator / oper | -- / equal |
| operd | shift / operd | doopn,rator / oper | doopn / equal |
| equal | shift / initd | rator / oper | -- / equal |
Each entry of the table has the form ``action(s) / next state''; -- means ``no action''. Thus, for example, when the machine is in state operd and the input is operator, it
Although the digital output device looks like a memory location, it really isn't one. However, your code may treat it like a memory location, so an operation like
does what you might expect. Just be careful that you access this location with byte instructions. A word or long will cause an error since the LEDs are mapped to an odd memory address.addi.b #$01,$B00001
The digital output device can be used in conjunction with MooseLoad for debugging a program, using a technique analogous to that of inserting print statements into a C program. Suppose that you have linked the program for MooseLoad, and downloaded it via TeraTerm (i.e. you are not using the XRAY monitor). Suppose further that you put the following instructions into your program:
The first instruction will cause the LEDs to display a binary ``1'', and the second will enter the MooseLoad debug mode. If each such sequence of instructions that you insert sends a different byte to the digital output, you can tell exactly where you are in your program. (The trap #5 instruction causes your program to jump to MooseLoad's debug mode.)move.b #$fe,$B00001 trap #5
Once in debug mode, MooseLoad allows you to display and modify registers, return to your program, or go to the main MooseLoad menu. From the main menu, you can display and modify memory, restart your program at the beginning, or return to debug mode and then go back to the instruction following the trap.
You will need to consult the map file and program listings produced when you built your program in order to find out where things are in memory. This involves hexadecimal arithmetic, and an understanding of the listings themselves.
While MooseLoad may appear primitive, its capabilities are quite representative of the those found in any monitor or single board development system. Often it is easier to use these simple capabilities than it is to live with the restrictions and complexity of the XRAY monitor.
You cannot use backspace characters to correct typing mistakes. If you study the state table given above, however, you will see that it really isn't necessary -- if you make a mistake, simply type the correct characters. Numbers can be corrected by typing more digits, because only the last two digits typed are held in buf. Operators can be corrected by typing another operator, because only the last operator typed is remembered.
MooseLoad uses the same strategy for dealing with numbers: Although it won't accept backspaces, it only keeps the last 8 digits you type.
Implement the 2's-complement calculator calculator using some combination of C and assembly language modules, in conjunction with the C-coded character input module. Your implementation must be made up of at least two source files in addition to inchar.c.
You will need to create a Makefile to build your program. Look back at the Makefiles provided to you for previous assignments. They all follow the same pattern, and you should be able to select the components you need without knowing much about how make works. If you are having problems, or would like to know more about make, click here.
You have been introduced to several ways of building and testing programs
on the laboratory machines.
Choose one that is appropriate and refer back to an earlier assignment for
detailed instructions if necessary.
Questions
| Instructor | Revision 1.38 (2007/08/27 00:15:44) |