## Project 2: Hex to Octal

### Objective

The objective of this programming project is to practice designing your own loops and branching code in assembly language and to gain greater familiarity with the i386 instructions set.

### Assignment

Write an assembly language program that prompts the user to enter a string to be interpreted as an 8-digit hexadecimal number. Your program must convert the ASCII string representation of this hexadecimal number into a 32-bit unsigned binary number. Then, your program must prepare and store an ASCII string for the octal (base 8) representation of the same number and print it out.

Your program should generate an error if the input string contains a character that is not 0 through 9 or A through F (except for the linefeed at the end). You may disallow lower case 'a' through 'f' in the hexadecimal representation. You may also assume that any input string that does not have exactly 8 characters is invalid (not counting the linefeed).

### Example:

Enter an 8-digit hex number: A1B72FE3 Octal: 24155627743

### Implementation Issues:

1. The user input has a linefeed character at the end. You do not want to consider this character when you convert from a hexadecimal (ASCII) string to binary.
2. It is OK to print out extra leading zeroes for the octal representation of the number.
3. You will find the shift left and shift right instructions SHL and SHR especially useful.
4. You should use the AND and OR instructions for masking.
5. You should not use the MUL or IMUL instructions. Multiplication is not necessary.
6. Note that the character 'A' does not follow the digit '9' in ASCII. Remember this when you convert the hex string to binary.
7. Eight hexadecimal digits is exactly 32-bits, but 32 bits isn't exactly 11 octal digits (that would be 33 bits). You should use a special case to process the 2 most significant bits when you convert from binary to octal (ASCII) string.
8. You must use a loop to convert from a hexadecimal (ASCII) string to binary and a separate loop to convert from binary to a octal (ASCII) string. I.e., you must not just repeat code 8 times when converting from hex to binary or repeat code 10 times when converting from binary to octal.

### Turning in your program

Use the UNIX script command to record some sample runs of your program. You should use inputs that result in a variety of octal string outputs and also inputs that demonstrate the error checking features of your program.

Continue running script to record yourself using the gdb debugger to examine the 32-bit memory location or the 32-bit register that holds the binary equivalent of the user input after conversion. Print out the value in hexadecimal and in octal.

You should submit two files: 1) your assembly language program and 2) a typescript file of your sample runs and your gdb session. The UNIX command to do this should look something like:

submit cs313 proj2 hex2oct.asm typescript

Last Modified: 20 Sep 2012 07:55:09 EDT by Richard Chang
to Fall 2012 CMSC 313 Homepage