As already explained in the task description, the main goal of this course is to build a robot that is able to read bar code cards containing instructions for a computing machine that operates on a stack.
This so-called stack machine is capable of performing basic arithmetic and executing text-to-speech.
The following section is about the requirements and specifications for such an machine.
As stack machines are Turing-complete per definition, but we don’t want to proof this for the given instruction set, let’s simply assume that stack machine here is an alias for a pushdown automaton.
The stack machine accepts 6-bit machine words as input.
Depending on the most significant bit (MSB)
$m$ of such word, the following five bits either represent an operand, an instruction or a character.
After initialisation, the stack machine starts with an empty stack and an overflow flag set to False.
010010 = DEL
110010 = O
$m$ is not set check the second bit
$n$ is also not set simply take the remaining bits as the binary representation of an operand.
A single operand can have a value in the range
$[0\ \dots\ 15]$.
Note that the value read shall be stored in an 8-bit integer internally. Pushing an operand resets the overflow flag to False.
$m$ is not set and
$n$ is set you have to look up the corresponding command from the instruction set and proceed with further processing.
This may include fetching the correct number of operands from memory, performing the action or calculation and in case a result is generated store it back into memory.
In the following we will refer to operands on the stack by
$n$ always stands for the current position of the element on top, i.e. the size of the stack.
Any operation removes the used operand from the stack and pushes the result to it.
$m$ is set the following 5 bits either are a character, SPEAK or a NOP command.
During the execution of code an exception may break the normal flow of the program.
An exception is defined as every condition that leads to undefined behaviour.
For example, the programmer may ask the machine to perform an ADD instruction although there are no operands on the stack.
Obviously, the instruction cannot be executed and the exception
operand mismatch occurs.
Running the program any further would not make sense in most cases, as following calculations can be expected to contain errors as well.
As a consequence, the machine is simply being halted when encountering an exception.
Please distinguish between undefined and other defined conditions carefully. An integer overflow for instance is accurately specified and therefore no exception.