![](https://csdnimg.cn/release/download_crawler_static/7397363/bga.jpg)
10
assemble it, and then run it, (c) create or load a new machine instead of the Wombat1,
or (d) quit.
To quit CPU Sim, just choose “Quit” from the File menu. You may be asked
whether you want to save the changes to the Wombat1 or an assembly language
program. Click “No” for each of these and then CPU Sim will quit running.
CREATING NEW MACHINES IN CPU SIM, A Tour using the Wombat1
To demonstrate how to use CPU Sim to create a new hypothetical machine or
CPU, we will outline the construction of the “Wombat1” machine used in the first tour.
We will only demonstrate some of the principles of constructing a new machine since
completing the whole machine here, especially all the microinstruction and machine
instruction specifications, would be somewhat time consuming.
Start up CPU Sim or, if you left it running after the previous tour, choose “New
machine” from the File menu. The default new machine has no registers, no memory,
and no machine instructions.
The machine we will now construct, the Wombat1, is a single-accumulator
machine using six registers: acc (the accumulator), pc (the program counter), ir (the
instruction register), the mar (memory address register), mdr (the memory data register),
and the status (the status register). The basic structure of the Wombat1 is shown in
Figure 4. The status register is 3 bits wide, the pc and mar are 12 bits wide and the other
three registers are 16 bits wide. The Wombat1 also has a main memory (RAM)
consisting of 128 bytes. The arrows in the figure indicate the movement of data by the
microinstructions.
The pc contains the address of the main memory location that contains the next
instruction to be executed. In the fetch sequence (the first part of every machine cycle),
the next instruction to be executed is copied into the ir, where the instruction is
decoded. Then the instruction is executed, which completes the machine cycle. This is
followed repeatedly by more machine cycles, each consisting again of the execution of
the fetch sequence followed by the execution of a machine instruction.
All computations are done in the acc. The mar and mdr are the registers through
which data is transferred to and from the main memory.
There are 12 machine instructions for the Wombat1, each associated with a 4-bit
opcode. These instructions are: HALT (stop), READ (get input from the user), WRITE
(send output to the user), LOAD (transfer data from the main memory to the acc),
STORE (transfer data from the acc to the main memory), ADD (add a value from the
main memory to the value in the acc, putting the result in the acc), SUBTRACT,
MULTIPLY, DIVIDE (all similar to ADD), JMPZ (if the value in the acc is 0, jump to a
new location to obtain the next instruction to be executed), JMPN (if the value in the acc
is less than 0, jump to a new location to obtain the next instruction to be executed),
JUMP (jump to a new location unconditionally).