The purpose of this MAL programming assignment is:
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
getc instruction for reading
user inputputc and puts
instructions for displaying outputdone
instruction) from the program.
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.
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.
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.)