CS 2700: Assembly Language and Computer Architecture

Spring 2015 - Lab 4

Due 5/13 by 5 pm

  1. Log in with your CS lab user name and password so that you will be able to save any files you work on for later use. (On Windows, you will need to save your files to the T: drive to be able to use them later.)

  2. "java -jar /Applications/MarieSim/marieSim.jar" is the command to run MARIE from the command line in the Mac OS; double-clicking on MarieSim.jar in a Mac Finder window will also start it. In Windows, open the Windows Explorer, go to "Computer", then the "Bootcamp" drive, then "Program Files", then "MarieSim" and double-click on marieSim.jar.

  3. Write and run a complete MARIE assembly program to do this:

    Read in and store 12 integers, each in the range 0-9 (inclusive) - the UPC code (the numbers at the bottom of a bar code) for some product
    Calculate the UPC check digit
    Output the check digit to the user
    

  4. UPC codes (Universal Product Codes) are printed on many products in our daily lives. The numbers in the code are encoded into black and white bars and printed on the product packaging, for scanners to read. In every UPC code, the final (rightmost) digit is a "check digit," included to help prevent small errors in reading, copying and scanning.

    The "check digit" in a UPC code is the 12th digit, printed to the right and slightly below the rightmost black bar.

    1. First, calculate the sum of the odd digits (the first, third, fifth, etc). The very first digit in the UPC code is printed slightly to the left and below the leftmost black bar on the UPC label. It is visually separated from the second digit by a small gap.
    2. Multiply that sum by 3.
    3. Add to this number all the even digits in the UPC code (the second, fourth, etc), not including the final check digit itself.
    4. Divide this number by 10 and take the remainder. (Or subtract off 10 repeatedly until the result is less than 10.)
    5. If the result is zero, you're done and that is the check digit.
    6. If the result is not zero, subtract it from 10 and the result is the check digit.
  5. For example, the UPC code on a pack of cards in my office is:

         0 73854 60088 7
    
         check = 0 + 3 + 5 + 6 + 0 + 8 = 22
         check = 22 * 3
         check = 66 + 7 + 8 + 4 + 0 + 8 = 93
         check = 93 % 10 = 3  (93 modulus 10)
         check = 10 - 3 = 7, which is the check digit
    
    

  6. MARIE does not have a division operation, so you may want to consider repeated subtraction.

  7. A significant part of the grade for this lab will be determined by good programming style. Good programming style, in this case, will include carefully decomposing the problem into meaningful units of work, naming those units well, use of JnS to appropriately navigate around your source code, and, of course, clear, readable comments.

  8. Every single line of code in your program must have a comment clearly explaining the purpose of that line. No exceptions. The comment on the top line of the source code file must include your first and last names. (Lines of source code specifying variable values should be commented appropriately, as well.)

  9. Be careful to test your program on several real UPC codes. The professor has several items you may use if there are no bar codes on any items in your backpack.

  10. Upload the working and tested source code (.mas) to the CSHomework system by the assignment deadline.

Last updated 4/30/2015