University of Wisconsin Computer Sciences Header Map (repeated with 
textual links if page includes departmental footer) Useful Resources Research at UW-Madison CS Dept UW-Madison CS Undergraduate Program UW-Madison CS Graduate Program UW-Madison CS People Useful Information Current Seminars in the CS Department Search Our Site UW-Madison CS Computer Systems Laboratory UW-Madison Computer Sciences Department Home Page UW-Madison Home Page

Program 2

CS/ECE 354, Fall 2003


Send e-mail questions to Nitin Agrawal, nitina@cs.wisc.edu
Due Friday, October 24 before 5pm


Purpose

The purpose of this MAL programming assignment is:

Program Statement

Write a MAL program that computes a "signature" on a string of characters. The user is to enter a string of up to 20 characters, which the program places in an array. The newline character that ends the string is not placed into the array. The program computes the signature of this string and prints it out.

We will use a signature that is defined as the 32-bit value that results from a combintation of shifts and exclusive or operations. In essence, we are using software to simulate a linear feedback shift register, which produces a digital signature. (Such a signature is useful for summarizing data to guard against accidental or intensional corruption. If data continues to match its signature, it is likely to be unmodified.)

Here is pseudocode to define how we will compute the signature:


   .data
   signature:  .word  0
   mask:       .word  0x000000af # a primitive polynomial

   for each bit of the string (called the input bit)
   {
     if the most significant bit of the signature == 0
     {
         signature = signature rotated left by one bit
	 least significant bit of signature =  the input bit
     }
     else  # the msb of the signature was a 1
     {
         temp = signature logically left shifted by one bit
	 signature = temp XOR mask
	 least significant bit of signature =  NOT(the input bit)
     }
   }

So that each program computes the same signature given the same string, the bits of the string must be used in a fixed order. If the user types "abc", then the first input bit is the most significant bit of the character 'a', the second bit is the next most significant bit of the character 'a', and after the bits of the character 'a' are all used, the bits of the character 'b' are used in the same ordering as 'a'. Diagrammed, this is

           'a'         'b'         'c'          character
          0x61         0x62        0x63         ASCII (in hex)
        01100001     01100010    01100011       ASCII (in binary)
        ^ ^    ^     ^                  ^
        | |    |     |                  --- last input bit
        | |    |     --- 9th input bit
        | |    --- 8th input bit
        | --- 3rd input bit
        --- 1st input bit

To make printing of a signature easy, we will pretend that the signature is a 32-bit, two's complement integer. The Chapter 8 lecture notes contain a simple MAL program that prints out an integer. You may use this code, extending the code to also handle the printing of a negative integer.

Here is a sample run of the program. Characters entered by the user are printed in bold. NOTE: Earlier version of this contained incorrect answers for some strings. The incorrect ones are now corrected.

Enter a string of 20 or fewer characters.  End the string
with the newline character.
abc 
The signature on this string is 6382179

Here is a second sample run of the program.

Enter a string of 20 or fewer characters.  End the string
with the newline character.
aaaaaaaaaabbbbbbbbbb 
The signature on this string is 381753894

Here is a third sample run of the program.

Enter a string of 20 or fewer characters.  End the string
with the newline character.
aaaaaaaaaabbbbbbbbbbc 
The signature on this string is 381753894

Requirements

  1. The program should run once and exit.
  2. Use MAL instructions only! Some examples of the things that are different in MAL:
  3. Your program must contain adequate comments (documentation). Such comments include your name, student ID, and section number at the top of the program. They include a description of the program, as well as variable descriptions, comments about the code itself, and a description of each procedure or function. See Guidelines for Programs for further clarifications on documentation.
  4. Use a one-dimensional array for saving the string. Organize your code such that it contains three sections. The first section reads the user input, and places the characters into an array. The second section computes the signature. The third section prints the signature.
  5. Program output should look like the sample output given.
  6. If the user enters more than 20 characters, the program is to ignore further characters, and just compute the signature on the first 20 characters. Like Program 1, there should be exactly one exit point (done instruction) from the program.
  7. Do not implement procedures.

Hints

  1. Some students may benefit from first writing this program in a high level language and then translating the program to MAL.
  2. The user interface in the simulator (simp) leaves something to be desired. It presents no features for debugging.

    A much more powerful user interface for the simulator can be accessed by invoking the simulator with sim (instead of simp).

    This user interface will allow you to set breakpoints and single step through your code. It will also show you the contents of registers for your program.

    sim should be used to run and test your MAL program.

    The pathname to the simulator is the same for sim as for simp. Note that the ability to use this improved user interface across the network (while using SecureCRT or ssh) is not guaranteed. An X-server must be available. See the FAQ page for more details, if you are interested.

  3. There is a program that you may use to determine if your MAL program contains any non-MAL operands or instructions.

    The program is called MALtester, and it is located in the same directory as the simulator.

    An example usage of the program is

                     MALtester myprogram.s
    
    where myprogram.s is an example file name of MAL source code.

Handing In the Program

Turn in your MAL program by running the script:


  handinP2 program2.s

where program2.s is an example name of the file containing the source code. The handinP script submits your program for you. No printout will be turned in. (We assume that you have put /p/course/cs354-common/public/bin in your path by now.)