Homework 1, Calculator

Short Description:

Write a program which will act as a simple calculator.

This assignment is worth 100 points.

Goals

When you finish this homework, you should:

Formal Description

Create a program which will act as a simple calculator. This calculator has an accumulator, four memory locations and should support the operations in the table below. The result of all computations are stored in the accumulator. The calculator only supports integer operation.

Operation # Operands Comment
+ 2 Addition
- 2 Subtraction
- 1 Negation
* 2 Multiplication
/ 2 Integer Division
% 2 Remainder
^ 2 Power, the second operand must be non-negative
load 1 Load the accumulator from a memory location
store 1 Store the accumulator to a memory location
print 0 Print the value in the accumulator
system 1 Set the output system
+= 1 Add operand to accumulator
-= 1 Subtract operand from accumulator
*= 1 Multiply accumulator by operand
/= 1 Divide accumulator by operand
%= 1 Remainder of accumulator divided by operand
^= 1 Raise accumulator to operand, the operand must be non-negative.
dump 0 Print the value of the accumulator and all registers.

Your calculator should support number representation in the following number systems:

Decimal (dcml)
The decimal number system consists of the digits 0 through 9, with normal associated values.
This is a position based number system where d1d2d3 = d1 × 102 + d2 × 101 + d3 × 100.
The number 23410 = 234dcml.
There is a unique representation for each number.
Binary (biny)
The binary system consists of the digits T and F, where Tbiny = 110 and Fbiny = 010.
This is a position based number system where d1d2d3 = d1 × 22 + d2 × 21 + d3 × 20.
The number 23410 = TTTFTFTFbiny.
There is a unique representation for each number.
Hexadecimal (hexa)
The hexadecimal number system consists of the digits 0 through 9 and A through F.
A represents 1010, B represents 1110, ... F represents 1510.
This is a position based number system where d1d2d3 = d1 × 162 + d2 × 161 + d3 × 160.
The number 23410 = EAhexa.
There is a unique representation for each number.
Trinary (trin)
The trinary number system consists of the digits 0 through 2, with normal values.
This is a position based number system where d1d2d3 = d1 × 32 + d2 × 31 + d3 × 30.
The number 23410 = 22200trin.
There is a unique representation for each number.
Modified Urnfield (murn)
The Urnfield number system consists of the marks / and \. In addition, we will add the marks (,), [,] and 0.
In the modified system, 0murn = 010, / = 110, \ = 510, ( = 2510, )= 12510, [ = 62510 and ] =312510.
This is a position based number system, where digits are listed in ascending order. {/,\,(,),[,]}, with as few digits as possible.
The number 23410 = ////\(((()murn.
There is a unique representation for each number.
Modified Mayan (mmay)
The Modified Mayan system uses the following symbols 0,., |, and ,.
This is a position based number system where d1,d2,d3 = d1 × 202 + d2 × 201 + d3 × 200. (We will use , to separate digits)
The number ... (310) and the number .,.,. (42110) are different numbers in this system.
The number 23410 = .||,.|||mmay.
The number 23410 = .||,....||mmay.
There is a unique representation for each number.
Positionless (posi)
This system uses the symbols I, X, M, C, K, G, T, P
Iposi= 10010, Xposi= 10110, Mposi= 10210, Cposi= 10310, Kposi= 10410, Gposi= 10510, Tposi= 10610, Pposi= 10710
This is a positionless number system where the value of the symbols are added.
The number 23410 = MMXXXIIIIposi = IIIIXXXMMposi = IXMIXMIXIposi = IXIMXMIXIposi
There is not a unique representation for each number.

Operands

All operands follow the operator. Operands and operators are delimited by spaces. Each operation begins on a new line operator first, followed by operands, followed by optional comments. Operands will be either a number or a memory location. Memory locations are labeled A, B, C and D. Numbers will be given in the form representation: name, where representation is a number in one of the representation system described above and name is the four letter name for the representation system. All of the following are valid The result of all mathematical operations are stored in the accumulator.

The system operator will have a single operand, the four letter name of a system which will be used for all output. The default system should be dcml.

All input data should be validated. If an invalid input value, operator or operand is encountered, the system should print the input line, followed by a diagnostic error message. The system should continue processing commands.

Example

The following is a valid set of input.

+ 1:dcml 1:dcml The accumulator should now contain a 2
store A         Register A should now contain the value 2
+ A //:murn     The accumulator should now contain a 4
store B         Register B should now contain the value 4
system biny     Change the output to binary
print           Should print TFF:biny to the screen
system trin     Change the output to trinary
print           Should print 11:trin to the screen
+ B FXF:biny    Should print an error message that X is an invalid binary digit
dump            Should print the value of the accumulator (4) plus the 4 memory locations A:2, B:4, C:0 , D:0

Discussion

Required Files

You should submit the following in a tar file: You should not submit

Submission

Please create a tar file containing the files described above. Email this file to danbennett360@gmail.com by class time of the due date.