<<< Invoking a C Function from Assembly | Index | Stack Machine Example >>> |
Your assignment is to build a small command-based stack machine.
Here is the minimal set of commands that your machine must understand:
push N ; PUSH( N ) add ; PUSH( POP() + POP() ) hlt ; HALT the machine start ; START the machine
where
PUSH command pushes decimal value N on the stack. If stack overflow condition is detected, the comand prints an appropriate error message and goes into a HALT state.
ADD command pops two values from the stack and computes their sum. The result is pushed back on the stack. If less than 2 values are present on the stack, the comand prints an error message and goes into a HALT state.
HLT command stops the execution and places the machine in the HALT state.
START command sets the instruction pointer to the first instruction, and switches the machine into a RUN state, which executes the loaded program.
<<< Invoking a C Function from Assembly | Index | Stack Machine Example >>> |