This assignment must be submitted as a single file for Assignment 2 of the CSCI 255/ECE 109 section on UNCA moodle by 5:00 PM on Friday, 6 March.
If you would like to review a presentation of a similar problem, take a look at Problem Session 2. You can also download an archived lecture that discusses this problem.
This assignment is a "real" world problem and, as such, isn't simple. The problem is to design a finite state machine that determines if an input sequence is a legal integer constant in the C++ programming language. C++ allows integer constants to be expressed in three forms.
Furthermore, integer constants can be followed by suffixes composed of the letters 'u' or 'U' to indicate the integer is unsigned or 'l' or 'L' to indicate the number is long. Since a number can be both unsigned and long, 'ul', 'lu', 'Ul', 'Lu', 'uL', 'lU', 'UL', and 'LU' also legal two-letter suffixes.
This means that 2009
, 03731
,
and 0x7D9
are all legitimate ways of writing
the number 2009 in C++ (and C).
With suffixes, 2009l
, 2009ul
, and
2009LU
are also legal.
The following are not legal constants.
|
Must contain at least one character. |
5 6 |
Can't contain blanks at beginning, middle, or end. |
080 |
No 8's or 9's in octal numbers |
-255 |
Not a constant, but an operator applied to a constant. |
2009LL |
Legal in C99 standard (as a long long), but not in C++ |
#!^&*@#$* |
Watch your language! |
Your finite state machine processes the characters as they are input.
Consequently, a seven-character input sequence like 0x7D9LL
will be judged valid at the end of the clock cycle
for the five partial sequences
0
, 0x7
, 0x7D
0x7D9
, 0x7D9L
but not
at the end of the cycle for 0x
, 0x7D9LL
, or the initial
state (empty string).
Technically, the input to your circuit should be a seven-bit ASCII encoding. However, seven bits would be too much; so we assume that your circuit will be fronted by a special encoder that reduces the number of inputs from seven to three bits. The meaning of these three bits is shown in the following table.
Binary inputs | ASCII character input | ||
---|---|---|---|
0 | 0 | 0 | Character '0' |
0 | 0 | 1 | Characters '1' to '7' |
0 | 1 | 0 | Characters '8' or '9' |
0 | 1 | 1 | Characters 'A' to 'F' or 'a' to 'f' |
1 | 0 | 0 | Characters 'u' or 'U' |
1 | 0 | 1 | Characters 'l' or 'L' |
1 | 1 | 0 | Characters 'x' or 'X' |
1 | 1 | 1 | Any character not covered by the above cases |
If you want an example of how this works, you can download a Perl script which reads input strings and prints out the three-bit input encoding and the expected one-bit binary output for them.
Here'a an example of running this program on our sample input 0x7D9LL
:
bash-3.2$ CIntCheck.pl Enter an empty line when you've had enough 0x7D9LL string=> 0 x 7 D 9 L L in2bit=> 0 1 0 0 0 1 1 in1bit=> 0 1 0 1 1 0 0 in0bit=> 0 0 1 1 0 1 1 outbit=> 0 1 0 1 1 1 1 0
If you are running Windows on your computer, you may need to download a Perl interpreter to run the sample program. Do not attempt to use this script as a model for your solution because (1) Perl is a write-only language and its programs are inscrutable, and (2) the script uses regular expressions rather than finite state machines to solve the problem.
This is actually the first part of a two-part assignment. For this part you should turn in a table similar to the "English" finite state machine specification presented for the "Nabs" machine in the February 5 lecture. If you wish, you can start with an Excel spreadsheet that contains this information. You could also turn in a scanned copy of a drawn finite state machine.
You may turn in either a text file, spreadsheet, or PDF file into moodle for this assignment.