Evaluating Hamming Code Words

Supplementary procedures:

Your program will do each of the following:

  1. Read a text file named hamming.txt containing 1 or more ASCII binary strings. Each string is on a separate line, and it contains a series of 16 ones and zeros that represent a Hamming code word. Actually, the last 4 bits are zeros and are not used. Display the code word on the screen with a label. For example: "Reading code word: 1010110010100000".
  2. Convert each ASCII binary string to a 16-bit binary integer, in big endian order. For example, the string "1111000010100010" would be translated to F0A2h. We will call this the codeWord.
  3. Evaluate the parity of the four bit groups of this code word, using techniques discussed in class. The groups are numbered: Group1, Group2, Group4, and Group8. For each group having odd parity, add the group number to a sum. The sum will identifiy the bit number that has been altered.
  4. If the code word is correct as is, display a message saying "no errors found". If an error was found in the code word, display a message indicating the position of the altered bit, such as: "parity error found in position 4".
  5. Toggle the incorrect bit and redisplay the codeWord in binary. For example: "error corrected: 1010110010100000".
  6. Continue to the next code word in the file, repeating the process. The program ends when the end of file is found.
For this problem, bits are numbered from left to right, starting with 1 and ending at 16.

The Data File

Each record of the test data file contains exactly 18 bytes (16 bytes of digits, plus hidden CR, LF characters) Here are the contents of hamming.txt:

0110100011110000
1110100011110000
0110110011110000
0110100011100000
0110010111010000
0100010111010000
0110110111010000
0110010110010000

It contains two different code words, with examples of errors in different positions. Your program should work with any valid Hamming code words. Download and run my demo program. The ZIP file also contains hamming.txt, which you should use to test your own program. My solution program generates about 30 lines of output, so you might want to set your DOS window properties to enough lines to avoid losing scrolled text. Also, un-check the "Close Window on Exit" option in the window properties dialog.

When I test your program, I will use a a new version of hamming.txt. Important: your program must open a file named hamming.txt in the current directory.

Grading Scheme

Your grade will be based on how early you turn in a perfectly working program. In the following table, the grade you can earn goes down with each successive submission date. Immediately after each submission date, I will publish on my web site, the source code for the code samples shown in the right column. For example, on Nov 16, I will publish the contents of my EvenParity and ReadCodeWord procedures:

Submit Date Max Grade Published Code Samples
Nov 8 110 none
Nov 15 100 none
Nov 27 80 EvenParity, ReadCodeWord
Nov 29 60 FixCodeWord, TestCodeWord

Suggested Reading

Evaluating Parity

The AND, OR, NOT, XOR, and TEST instructions all affect the parity flag. For example, if you do the following, it will set the parity flat to PE (even) or PO (odd), depending on the bits in the lowest byte of the destination operand:

   mov al,10101110b
   or al,al				; Parity = odd (five bits are set)

What about 16-bit numbers? Bummer, the Parity flag only works for byte values. To evaluate the parity of a 16-bit register such as AX, you can check the parity of AH and AL separately, and then combine the two results. Here's an interesting property of integer addition that will help you:

   even + even --> even
   odd  + odd  --> even
   odd  + even --> odd
   even + odd  --> odd
In my own solution program, I have a function named EvenParity that sets the Zero flag if the word in AX has even parity.