PJRC.COM Offline Archive, February 07, 2004 Visit this page on the live site |
| ||
Shopping Cart Checkout Shipping Cost Download Website |
Home | MP3 Player | 8051 Tools | All Projects | PJRC Store | Site Map |
You are here: OSU8 Microprocessor CPU Programming Software Simulator | Search PJRC |
|
When you're designing a new CPU, you just can't run the code. Worse yet, how can you discover something is lacking in the instruction set until you write some code and try running it? Though these web pages are separate, as if each step was done before beginning the next, in reality writing the using this software simulator lead to revisions in the instruction set, causing assembler and simulator to change.
Later, the software simulator turned out to be absolutely necessary for evaluating the circuit simulations. Code could be run in the software simulator, and in the simulation of the actual hardware, and by comparing the results mistakes in the hardware could be identified.
The best strategy I could devise was to make a self-contained
disassebler, check it very carefully, and use it from both the
assembler and simulator for display. If the assebler generates
an incorrect opcode, the separate disassembler would be likely
to display the mnemonic and operands of that incorrect opcode. Likewise,
if the simulator does the incorrect action of an opcode, it would
still be likely to display the correct text, making the bug as
obvious as possible. This separate disassembler appears in the
file osu8dasm.c
.
The heart of the disassebler is a function called
one_instruction()
, which executes one instruction.
The machine state is stored in global variables, including the
program counter, so this function requires no input variables.
The main()
function runs in a loop, accepting
interactive input from the user, and calling functions to
implement the user interface.
add text from an example run of the simulator, with some comments explaining key points.