DUE DATE: Friday, October 11, 2002, 5:00 pm
(no late submissions accepted)
Summary
This project introduces students to ASCII / binary conversion,
hexadecimal number manipulation, logical operations, and user input / output.
Your task is to write an assembly language program that would serve
as a hexadecimal calculator. The program would allow the user to input a
hexadecimal arithmetic or logical expression, perform the requested
operation and then display the hexadecimal result. The operations your calculator should
support are:
- Arithmetic: addition (+), subtraction (-), multiplication (*), division (/)
- Logical: binary AND (&), binary OR (
), binary XOR (
)
Assume all numbers entered by the user are hexademical. Continue taking
input until the user presses ENTER without entering anything. For example:
$ ./hexcalc
Enter an expression: 10 - B
= 5
Enter an expression: A * A
= 64
Enter an expression: B1 | 5
= B5
Enter an expression:
$
Notes
- It is up to you to put restrictions on the syntax. For example, you
may require to user to put a space between the operands and operator (5 + 3) or accept input without spaces (5+3). It is up to you which
you choose, but make sure you print instructions telling the user what
to do. If you do not print any instructions, I will assume you program will
take both syntaxes. Another example would be the case of letters used for
some hex digits. (Do you allow upper case or lower case or both?)
- Make sure you check the validity of the user input. If the user inputs
hello or me + you at the prompt, your calculator should generate
an error. Also perform error checking - do not assume every operation
completed successfully.
- Allow numbers to be up to 32 bits in size (up to 8 hex digits).
- Split your code into several files; create and use a Makefile for your project.
Extra Credit
- (10 pts) Implement a binary negation operation (
). Note that this operation
only requires one operand, whereas all the other operators require two.
- (20 pts) Allow the user to input expressions with arbitrary number of operators
and operands. For example, 15 + FC + 108 - D7 and so on. Make sure you
follow operator precedence, i.e. perform multiplication before addition. If you are
feeling particularly adventurous, you can even allow parentheses.
What to turn in
Please submit your source code, Makefile, object file, and executable to your submit
directory for this class. (located under /home/submit/cs210.) In
addition please submit a printout of your source code to the instructor.
Alex Fedosov
2002-10-02