Project 2 - LMC Programming
DAT 2343 - Summer 2000
Synopsis
- Write LMC mnemonic instructions for a program, using the supplied
pseudo-code.
- Assemble by hand your mnemonic instructions into LMC numeric codes.
- Enter your codes and test your program
in the LMC simulator under
Windows.
- Hand in an envelope containing a diskette and
printout of your working program.
Your program should read a sequence of numbers (after all, the LMC can only
input numbers!) and interpret the numbers alternately as numeric operands and
numeric codes that indicate arithmetic operations to be performed on the
numeric operands.
Keep a running total and output the results of the arithmetic (the running
total) as you read each new numeric operand. When the program is done,
output a count of the number of numeric operands that were input.
For example, suppose we had the following sequence of input values:
005 020 006 020 007 030 008 090
We want our program to interpret this 8-number sequence as the following
8-term formula:
5 + 6 + 7 - 8 QUIT
To do this, our program must interpret every second input value as a code
to perform an arithmetic operation. Note how 020 stands for
"+", 030 for "-", and 090 for "QUIT". Here
is the full table of numeric arithmetic operation codes to be recognized by
our program:
010 indicates a Reset-code
020 indicates an Add-code
030 indicates a Subtract-code
090 indicates a Quit-code
Let's look at each of the eight input values in the above example. The
odd-numbered input values are all numeric operands. The even-numbered
input values are all interpreted as arithmetic operation codes according to
the given table.
- 005 - The first input value to the program is always interpreted
as a number that becomes the current running total. After reading this
number, the program outputs the running total: 005.
- 020 - The second input value is a code for an arithmetic
operation to perform; in this case, 020 means an Add operation (+) that
will use the next input number.
- 006 - The third input value is the number to add to the current
running total. After reading and adding this number, the program
outputs the new running total: 011.
- 020 - The fourth input value is a code for an arithmetic
operation to perform; in this case, 020 means another Add operation (+)
that will use the next input number.
- 007 - The fifth input value is the number to add to the current
running total. After reading and adding this number, the program
outputs the new running total: 018.
- 030 - The sixth input value is a code for an arithmetic operation
to perform; in this case, 030 means a Subtract operation (-) that will use
the next input number.
- 008 - The seventh input value is the number to subtract from the
current running total. After reading and subtracting this number,
the program outputs the new running total: 010.
- 090 - The last input value is an operation code for "Quit
the program". After reading this code, the program outputs the
count of numeric operands read - 004 - and stops.
Consider another example of four input values:
020 020 020 090
Above, the arithmetic being performed is: 20 + 20 QUIT. The running
total output by the above example would be 020 and 040. The count of the
number of numeric operands read would be 002.
Here is another 8-number input example:
005 020 006 010 007 030 008 090
Above, the arithmetic being performed is: 5 + 6 @ 7 - 8 QUIT, where @
stands for a reset operation (numeric code 010). The reset
operation sets the current running total to be the next input number (007),
discarding the previous running total. The running totals output by the
above example would be 005, 011, 007, and 999. (The 999 comes from 7-8.)
The count of the number of numeric operands read would be 004.
Let's look at the pseudo-code that implements this program.
Use the following pseudo-code to develop your LMC mnemonic assembler
program.
Set the running total value to be zero
Set the loop counter to be zero
Set the operation code to be the Reset-code
Do {
input a number
If the operation code equals the Add-code
add the input number to the running total value
ElseIf the operation code equals the Subtract-code
subtract the input number from the running total value
ElseIf the operation code equals the Reset-code
set the running total value to be the input number
Else
set the running total value to be 999 (indicating an error)
Endif
output the running total value
increment the loop counter
input the next operation code
} while the operation code is not equal to the Quit-code
output the loop counter
Stop
Use the following constant values for your numeric operation codes:
010 indicates a Reset-code
020 indicates an Add-code
030 indicates a Subtract-code
090 indicates a Quit-code
Translate the given pseudo-code into LMC mnemonic instructions. Pay
attention to the details of the algorithm and the placement of each statement.
Your translated code must be in the usual labels/mnemonics/operands/comments
format. Do not optimize your code! Translate each pseudo-code
statement separately.
Important Notes
| Pick proper names for your variables. Do not use poor names such
as "first", "second", "A", "B",
"number", "num1", "num2", or
"value" (etc.). Use good names that reflect the functions
of the variables in the algorithm. |
| Variable names and labels must start with a letter and may not contain
blanks (same as in most programming languages). |
| No numeric arguments/operands are allowed when writing LMC mnemonic
instruction assembly language - write mnemonic instructions with labels
only. (For example, always write "LDA SUM" not "LDA
23". |
| When writing mnemonic assembly language code using labels, ensure that
all labels used have defined locations. |
| You can't use the same name for two different variables and/or
labels. All names must be unique (same as in most programming
languages). |
| Do not use the ORG pseudo-instruction. Code should begin at
mailbox location zero. |
Hand-assemble your LMC mnemonic instructions into the equivalent LMC
numeric codes. (Assign locations to all the instructions; build a label
table; translate the mnemonics into LMC numeric codes.)
Download the "son of LMC" Simulator program (see below) that
simulates the "Little Man Computer". This program should be run from
Windows 95/98. Run the simulator and enter your numeric codes into the correct
mailboxes. Run, test, and debug your program using the simulator.
When your program works correctly, use the simulator to save the numeric
codes on a diskette, using the file name given below.
Be sure to resave your modified numeric codes if you make changes to the
codes while in the simulator, and remember to modify your mnemonic
instructions to reflect any such changes before you hand in your
project. The mnemonic instructions you hand in must match the numeric
codes used in the simulator and saved on disk!
Submit an envelope containing a diskette containing a text file of your
saved LMC numeric codes and a text file of your mnemonic instructions.
Also include one printed copy of the mnemonic instructions file on a sheet of
paper. Follow the Hand In format given below.
The simulator comes in two versions. The basic version, available on
Alan Pinck's site, is known to work reasonably under Windows 95/98. The
enhanced version was enhanced by Algonquin student Christopher Hyne and
permits editing and other features. I recommend you try the enhanced
simulator first; if it misbehaves, tell me what went wrong and return to the
basic simulator.
The Enhanced Simulator can read the data files saved by the Basic
Simulator; but, the Basic Simulator can only read files saved in "old
format". (You will be asked which format you want when you use the
"save" feature of the Enhanced Simulator.) You may submit
files on diskette in either format. Enhanced format is easier to read,
since it is one mailbox per line.
Enhanced Simulator (FoSoLMC.EXE)
Download: FriendOfSonOfLMC.EXE
If you have Visual Basic 6.0 on your computer, you should only need the
actual program executable, given above. If you don't have Visual Basic 6.0
or the Visual Basic Runtime Libraries on your computer you will need to
download and install them using the (large!) Setup
Kit available here.
The above links are local Algonquin copies of the original files kept on Christopher Hyne's FoSoLMC site.
Basic Simulator (SonOfLMC.EXE)
Use this Basic Simulator if you can't get the Enhanced Simulator to work.
Download: SonOfLMC.EXE
The Basic Simulator doesn't have editing and other enhancements built
in. It requires certain Dynamic Link Libraries which are commonly
installed on many systems (all Algonquin College lab computers should have
these files). Specifically, this program was created using Visual Basic
version 4 and needs VB40032.DLL.
If your computer does not have any of the required files, you can
download a .ZIP version of the entire package including all support files
from:
Alan
Pinck Little Man Computer FTP site
The available files include: SonOfLMC.ZIP... the complete executable
package (4Mb) Son_P1.ZIP, Son_P2.ZIP, Son_P3.ZIP, Son_P4.ZIP... all the same
files as the above but broken up into 4 collections, each of which should
fit on a 1.4Mb disk.
Submit your Project in a labelled, unsealed, but closed
envelope. (If you seal an envelope, it becomes useless as an envelope
after I unseal it!)
Create and include in the envelope a copy of a diskette containing two
text-only files:
- File 1: A PROGRAM.TXT text file containing my Assignment
Submission label information followed by the five-column (plus comments)
code and mnemonic instructions of your LMC program.
- File 2: A P2CODES.LMC "save" text file from the
LMC simulator containing the LMC numeric codes of your assembled
program. I accept both Enhanced and Basic save formats. I will
load this code into my own simulator and test it.
Print the PROGRAM.TXT from the diskette and include the printout in
the envelope:
- Printout: Print a clear paper copy of your PROGRAM.TXT file
for submission in the envelope along with your diskette.
Please keep master copies of the diskette and printout; don't hand in
your only copy.
Text Files Only
For full marks:
| Follow my Assignment
Submission Standards. Put labels on everything! |
| All the submission files on the diskette must be plain text only.
Plain text is readable in Windows Notepad or DOS EDIT (or Unix/Linux vi).
Check the format of your files before you submit them. Do not submit
Word, WordPerfect, or HTML documents. |
| Use the exact file names given. The automated program I use to mark
these assignments will not find misspelled files on your diskette. Do
not place files in a subdirectory on the diskette. |
| Ensure that the document prints neatly - pay attention to margins, line
length, and consistent indentation. Align the columns carefully. |
Problems?
As with all questions and comments on course content, please post any
problems to the course discussion news group.
|