Evaluating Hamming Codes

Read about Hamming codes

Instructors Only

Solution program: solution.asm

Input data file: hamming.txt

Zip archive containing all required files

Strategy: This program requires reading through Chapter 7 in the book. They may need some help with opening and reading files. Other than that, the tutorial is fairly self-explanatory. The program can easily be completed in two weeks.

Evaluation: Very favorable response from students.

Description

Write a program that does the following:

  1. Display your name (and your partner's name) on the first line of the program's output.
  2. 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".
  3. 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.
  4. 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.
  5. 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".
  6. Toggle the incorrect bit and redisplay the codeWord in binary. For example: "error corrected: 1010110010100000".
  7. 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.

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)

The Parity flag only evaluates byte values. But you can get the parity of a 16-bit number by exclusive-ORing its two bytes together. For example, parity(AX) = AH XOR AL.