CMPUT 329

Lab #5

Multi-Mode Calculator

(2 weeks, pairs)

You may work in PAIRS for this lab.


Overview:

You are given the design for a finite state machine that implements a single-digit, single-mode calculator. You must expand this design to create a multimode, two-digit calculator. This lab aims to increase your familiarity with the design and implementation of sequential circuits through finite state machines.

Lab:

We have provided you with a finite-state machine that implements an infix calculator that uses the single digit on the XSA-50 board. Your task is to enhance this design in several ways.
  1. Expand the calculator's range of valid numbers to 2 hex digits, using the two LED digits on the XSTends board. This includes both input and output. The calculator should handle addition (+), subtraction (-) and multiplication (*). (We will not deal with division because a division operation requires a complex digital circuit.)
  2. Add a mode to the calculator such that, when the 'P' key is pressed, it accepts input in prefix notation. (Switch back to infix when the 'I' key is pressed.)
  3. Add a mode to the calculator such that, when the 'O' key is pressed, it accepts input in postfix notation.
  4. Display the current mode of entry on the upper LED display as 'O', 'P', or 'I'.
  5. Respond to the backspace key as an error correction. One press deletes the most recent digit entered, another deletes the other digit if entered.
  6. Respond to the delete key as a clear function (i.e. it should reset the calculator)
  7. Display the answer to the current statement when the Enter key is pressed (note: this is required because this is how we will test your design in the testbench)

Operation:

Apart from these characteristics, you may choose what to display, but you must document and justify any decisions you make and put them into your report. For example, you could have the LEDs display the digit entered once both digits have been inputted, but preferably each digit will be displayed as it is entered. In either case, document both the behavior that you implemented and the justification for your decision.

Quick review:

Infix Notation: The "normal order" we write equations, and the
normal way that inexpensive calculators work.
(eg. 4 - 3 = 1)
Prefix Notation: This known as "reverse Polish" notation - the operator
comes first, followed by the two operands.
(eg. -43= 1)
Postfix Notation The opposite of prefix - the operator comes after the
two operands.
(eg. 4 3 - = 1)

In infix notation it is trivial to detect the beginning and the end of operands; they are separated by operators. With the other two modes, however, more work is required. We need some standard way of knowing whether '4' '3' is the first operand, 43, or both operands, 4 and 3.

One solution would be to require a a control character (eg. enter) after every operand. This would produce something like the following:
Prefix: - \n 4 \n 3 \n (display 1 as result)
Postfix: 4 \n 3 \n - \n(display 1 as result)
Infix: 4 \n - \n 3 \n (display 1 as result)
While this convention makes the design of the finite state machine easier, it would produce a strange calculator that is not intuitive (requires 'enter' after each entry). Another solution is to simply enter all numbers as 2 hex digits. For example,
Prefix: - 04 03 = (display 01 as result)
Postfix: 04 03 - =(display 01 as result)
Infix: 04 - 03 = (display 01 as result)
04 - 03 = 01
- 04 03 = 01
04 03 - = 01

This allows for consistency (all modes have the same style of entry) without being too non intuitive. Thus we use this convention for this lab: all numbers will be entered as two digits, regardless of their size. Note that since there are no parenthesis or brackets, each operator must be executed in the order in which it is received (rules of associativity and precedence are not strictly observed). Also note that it is not possible to chain operations in prefix mode, but in infix and postfix mode, the last result will be used as the first operand unless delete is pressed between operations. E.g.:
01 + 01 + 01 + 01 = 04 (Infix)
01 01 + 01 + 01 + = 04 (Postfix)


**note: This review is a guide for you to understand the modes of entry in this design. It does not necessarily imply design constraints.

Questions:

  1. Can you parameterize your VHDL design to implement a calculator that uses any number of digits simply by changing a few constants? Why or why not? If you were to start this project from scratch, could your new design support this capability? If yes, explain how.

  2. What challenges and solutions do you see for expanding this design to a fully functional pocket calculator (ie, 12 digit numbers, floating point calculation, exponential notation for very large or small numbers, division, square root, percent, exponentiation, log functions, single entry memory, add to memory function, memory recall, etc...)? Is you design extendable, or would a complete redesign of the caclculator architecture be required? What kind of architectural features would you use if you wanted to ensure that you could expand this new architecture to a more complicated calculator, such as a finance calculator, a statistics calculator, or a programmable graphing calculator?

Bonus:

Alter the operation of the calculator so that all numbers do not need to be entered as two digits. This will require the following alterations: This does not change the basic functionality required above. The calculator can handle two-digit input without additional keypresses. Furthermore, the Enter key displays the result of the calculations as above.


Grading:


Resources:



[Return to CMPUT 329 Lab Home Page]
Created by Paul Berube , 2001; Modified by Paras Mehta, 2003