CMPUT 329

Lab #5

Multi-Mode Calculator

(2 weeks)


You may work in PAIRS for this lab.

Note that for this lab you will be working with the state machine editor GUI, and not directly in VHDL. (You will still be creating a schematic for the complete design, though.)

For this lab, you will be provided with a functional design for an infix calculator that uses the single LED digit on the xs40 board. The calculator is implemented using a state machine. Your task is to enhance this design in several ways:

  1. Expand the calculators range of valid numbers to 2 hex digits, using the two LED digits on the XSTends board. This includes both input and output. Display the operators (+, -, *, =) on the single digit on the xs40 (we will not use division in this lab). Note that you now need to add the '=' symbol for when you press 'enter'.
  2. Allow the calculator to function in prefix mode when the 'P' key is pressed. (Switch back to infix when the 'I' key is pressed).
  3. Allow the calculator to function in postfix mode when the 'O' key is pressed.
  4. Add the characters 'O', 'P' and 'I' to the symbol display, and show them when the mode is changed (until another symbol key is pressed).
  5. Allow the user to delete number entries using the backspace key (one press deletes the first digit, another press deletes the other digit (if 2 already entered)), and allow the operator to be changed by pressing a different operator before 'enter' is pressed.

Operation:

A reset/enable is attached to the RESET button on the XStends board. This is only used initially after the FPGA has been programmed. Otherwise, the 'del' key on the keypad acts as a clear button, returning the calculator to it's initial state. Numbers and operators are entered using the numeric keypad, plus the characters A through F (for hex digits). Modes are changed using the keyboard: Infix, pOstfix, Prefix. Modes may be changed at any time. If a mode change does not make sense at the current time (i.e. in the middle of a postfix operation change to prefix), put the calculator in an 'unknown' state (u on the symbol display, clear the number display), and return to operation only when clear (del) is pressed.

Quick review:

Infix: this is the "normal order" we write equations in, and the normal way that inexpensive calculators work.
4 - 3 = 1

Prefix: this is like "reverse polish" notation - the operator comes first, followed by the two operands.

- 4 3 = 1

Postfix: this is the opposite of prefix - the operator comes after the two operands.

4 3 - = 1

With infix notation, it is trivial to detect when operands start and end, since they are all separated by operators. However, in your design of the other modes, two operands are entered in a row. We need some (standard) way of knowing whether '4' '3' is the first operand, 43, or both operands, 4 and 3. There are two immediately apparent solutions. The first is to require 'enter' after every entry. So you would have something like

- \n 4 \n 3 \n (display 1 as result)
4 \n 3 \n - \n (display 1 as result).

However, this presents a problem when using the calculator in normal (infix) mode: either the calculator is non intuitive (requires 'enter' after each entry) or it is inconsistent (acts differently in this mode, by not requiring the 'enter' between entries). So, lets look at another option:  we simply enter all numbers as 2 hex digits. For example,

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 will follow this convention: all numbers will be entered as two digits, regardless of their size. Note that since there are no brackets, each operator must be executed in the order in which it is received (no order of operation is 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 clear (del) is pressed between operations. E.g.:

01 + 01 + 01 + 01 = 04 (Infix)
01 01 + 01 + 01 + = 04 (Postfix)

Resources:

Lab 5 starting design (calc) . Use this as your base, and build from here. Note that this project is targeted at the XS40 only, and uses only the single LED and 1-digit numbers.  Remember that the LEDs on the XS40 are active-high, but the LEDs on the XSTends board are active-low. You will need to follow the instructions for re-constituting a project that are described under Space management . This project was named calc, but feel free to rename it something else (how to do this is also listed at the end of  Space Management ).

 

[Return to CMPUT 329 Lab Home Page]

Created by Paul Berube , 2001