Project 2
Home Up Project 1 DEBUG Files EBCDIC Endian Wars LMC Negative Flag LMC Opcodes LMC Control Project 2
Updated:
2005-07-17 20:30

Project 2 - LMC Programming

DAT 2343 - Fall 2001

Synopsis

  1. From the given program description, write your own pseudo-code algorithm.
  2. Implement your pseudo-code algorithm using LMC mnemonic instructions.
  3. Assemble by hand your mnemonic instructions into LMC numeric codes.
  4. Enter your codes and test your program in the LMC simulator under Windows.
  5. Hand in an envelope containing a diskette with three files, and two printouts.

Program Description and Sample Input

Write the pseudo-code algorithm and LMC program that solves the following problem:

You are given three integers that represent vacation days.  The three integers may arrive in any order, and they may have any value from 000 to 999.  Your program is to first output the three vacation days in order from smallest to largest.  Next, output all the non-vacation days between the last vacation day (the largest integer of the three) and the first vacation day (the smallest integer of the three).  As you print all the non-vacation days, you must arrange not to print out the middle integer of the three, as it is also a vacation day.  You must print out all the non-vacation days from the largest day down to the smallest day, skipping over the middle vacation day.

Here's another way to express the same problem:

  1. Your program should read three numbers (after all, the LMC can only input numbers!) and store them in memory.
  2. Output the three numbers in order, from smallest to largest.
  3. Output all the integers between the largest and the smallest number, except the number that is the middle number of the three.  (Do not output the largest or the smallest either!)  Output the numbers in descending order, skipping over the middle number.

The method you choose to produce the output is entirely up to you.  The internals of the algorithm are not specified; you simply have to produce output that matches the given specifications.  You will hand in both your chosen algorithm and your implementation of it in LMC assembly language.  Duplicate submissions will constitute Academic Fraud; share your ideas, not your algorithm or your source code.

Sample Input and Output

Input:  005 001 008
Output: 001 005 008 007 006 004 003 002
Input:  013 016 010
Output: 010 013 016 015 014 012 011
Input:  101 100 102
Output: 100 101 102
Input:  999 998 998
Output: 998 998 999
Input:  000 000 000
Output: 000 000 000

Pseudo-Code and LMC Mnemonics

Write a pseudo-code algorithm that implements the given program specifications.  Pick proper names for your variables.  Use good names that reflect the functions of the variables in the original problem (vacation days). You will be handing this in.  (My pseudo-code was about 25 lines long.  I tested the logic of my pseudo-code by turning it into a C program that was about 31 lines long and a Perl program that was about 25 lines long.  You can try running it here.)

Translate your pseudo-code into LMC mnemonic instructions.  Pay attention to the details of your algorithm and the placement of each statement.  Do not optimize your LMC code!  (My resulting LMC program occupied about 70 mailboxes.  Yours may differ.  If it doesn't fit in 100 mailboxes, choose a shorter algorithm.  Less code is better code!)

Your translated assembly-language program must be in the usual labels/mnemonics/operands/comments format.  Do not optimize your code!  Translate each pseudo-code statement separately.  You will be handing this in.

LMC Mnemonics Notes

  1. LMC assembly language variable names and labels must start with a letter and may not contain blanks. (These are the same rules used in most programming languages.)
  2. No numeric mailbox arguments/operands are allowed to instruction mnemonics when writing LMC mnemonic instruction assembly language - write mnemonic instructions with labels only.  (For example, always write "LDA SUM" and never "LDA 23".)  "DAT" pseudo-operations are the only lines that are allowed to contain numbers (data).
  3. When writing mnemonic assembly language code using labels, ensure that all labels used have defined locations.  You may insert labels that are never actually used, for commenting purposes; but, do this sparingly as it can confuse people who read your code.  (Why is there a label on this instruction if it is never used?)
  4. You can't use the same name for two different variables and/or labels.  All names must be unique. (These are the same rules used in most programming languages.)
  5. Do not use the ORG pseudo-instruction (found in some assembly languages).  Code should begin at mailbox location zero.

Assembly, Testing, and Debugging

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 one of the LMC Simulator programs (see below) that simulate 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. (You can use a file to upload your LMC codes into the simulator.)  Run, test, and debug your program using the simulator.

When your program works correctly, use the simulator to save the LMC numeric codes on a diskette, using the exact file name given below.  (Warning: Marks are deducted for incorrect file names.)

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 and your pseudo-code 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, and the pseudo-code must match the mnemonic instructions!

Submit a diskette and print-outs according to the Hand In format given below.

Testing and Marking

I will be testing your program with many different inputs. Approximately half your mark is awarded based on your ability to handle all of my test cases - be brutal and thorough in your own testing.  The other half of the mark comes from adhering to project specifications and good programming practice.

Ensure that your program works correctly when run twice in a row (or more) without reloading.  That is, your program should still work correctly if, after the first test run, one simply pushes "Reset" and then starts it over again (with either the same or different input values).  Don't presume that your program will be loaded into memory anew every time it is tested; don't rely on the loading of the program to set the values of variables.  (Can you imagine using Netscape if you had to quit the program and reload it every time you wanted to view a new web page?)

LMC Simulator under Windows

The simulator comes in three versions.  The basic version, available on Alan Pinck's site, is known to work reasonably under Windows 95/98.  The first enhanced version was (re-)written by Algonquin student Christopher Hyne in 1999 and permits editing and other features.  The most recent version, including input and output queues, editing, and report facilities, is the Clone Simulator (re-)written by Algonquin student Mark Aleksandrov in the fall of 2000.  I recommend you try Mark's Clone simulator first, since it has working input and output queues.  If it misbehaves, try Chris's Enhanced simulator.  If that also misbehaves, return to the Basic simulator.  (Tell me what went wrong so that I can inform the authors.)

The Clone and Enhanced Simulators 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 Clone or Enhanced Simulator.)  You may submit files on diskette in either format.  Enhanced format is easier to read (and edit), since it is one mailbox per line.  Old format save files have no line end characters - all the mailboxes are saved end-to-end in one long 300-character line!

Clone Simulator (Mark Aleksandrov)

Try this one first.  Download and unZIP this file: clonesolmc.zip

Run the LMC.EXE executable and read the Help menu.  (If the file won't run, you may need to download the Visual Basic run-time libraries.  You can install them using the Setup Kit in the Enhanced Simulator, below.)

Enhanced Simulator (Friend-Of-Son-Of-LMC - Christopher Hyne)

Download and run the executable file: fosolmc-1.3.0.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 in Zip format.  Download it, unzip it, and then run setup.

Download and install the full setup kit if the fosolmc-1.3.0.exe program binary fails to run because of a "missing file" error.

The above links are local Algonquin copies of the original files kept on Christopher Hyne's F.O.S.O.L.M.C. site.

Basic Simulator (Son-Of-LMC)

Use this Basic Simulator if you can't get the Clone or Enhanced Simulators to work.  This version has no editing.

Download: sonoflmc.exe

The Basic Simulator doesn't have editing and other enhancements built in.  Like the Enhanced Simulator, this Basic Simulator requires certain Dynamic Link Libraries. Specifically, this Basic Simulator was created using Visual Basic version 4 and needs VB40032.DLL. These libraries are commonly installed on many systems (all Algonquin College lab computers should have these files). 

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 for the Basic Simulator include:

  1. SonOfLMC.ZIP... the complete executable package in ZIP format (4Mb).
  2. 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 floppy disk.

Hand In

Summary: Hand in 3 text files on one diskette; 2 printouts on paper.

Submit your Project diskette and print-outs 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 three text-only files (keep a backup copy):

  1. File 1: A text file named PSEUDO.TXT containing my Assignment Submission label information followed by your pseudo-code algorithm.
  2. File 2: A text file named PROGRAM.TXT containing my Assignment Submission label information followed by the five-column (plus comments) LMC code and mnemonic instructions of your LMC program.  (Marks will be deducted if the five columns in this file do not line up vertically.  Your program must be readable.)
  3. File 3: A text file named P2CODES.LMC that is the "save" file from the LMC simulator containing just the saved 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 both the PSEUDO.TXT and PROGRAM.TXT files from the diskette on paper and include the two printouts in the envelope:

  1. Printout 1: Print a clear paper copy of your PSEUDO.TXT file for submission in the envelope along with your diskette.
  2. Printout 2: 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 printouts; don't hand in your only copies.

Text Files Only

For full marks:

  1. Follow my Assignment Submission Standards.  Put labels on everything, including the diskette!
  2. All the submission files on the diskette must be plain text only.  (I accept any of DOS, Unix, or Macintosh plain text.)  Plain text is readable in Windows Wordpad, Notepad, or DOS EDIT (or Unix/Linux vi, or Macintosh TeachText).  Check the format of your files before you submit them.  Do not submit Word, WordPerfect, or HTML documents.
  3. 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.  Watch out for Windows hidden extensions; marks will be deducted for files named with double extensions such as PSEUDO.TXT.TXT.  Consult your Windows documentation for details on turning off hidden file extensions.
  4. Ensure that the documents print 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 you encounter to the course discussion news group.

 

Web Author: Ian! D. Allen idallen@idallen.ca      Updated: 2005-07-17 20:30

Internet Free Zone Level 1 logo Support free and non-commercial Internet.

Any Browser logo This site works best in Any Browser, a campaign for non-specific WWW.

Creative Commons License logo This work is licensed under a Creative Commons License.