Thursday, January 7, 2010

Simulator for a basic computer

This is simple simulator for the basic computer described in the book of Morris Mano "Computer System Architecture". Here professor Hyunsoo Yoo maintains a succinct but complete description of this computer, check it if you can't find the book. In special look for the lectures 5 (Basic Computer Organization and Design) and 6 (Programming the Basic Computer) that this simulator uses as foundation.

This basic computer is built from these components:

Component Bits Functionality
DR 16 Data Register
AR 12 Address Register
AC 16 Accumulator
IR 16 Instruction Register
PC 12 Program Counter
TR 16 Temporary Register
INPR 8 Input Register
OUTR 8 Output Register
MEMORY 16 Memory 4096 x 16
FGI 1 Input Flag
FGO 1 Output Flag
IEN 1 Interrupt Enabled Status
R 1 Interruption Status
I 1 Decode Bit
S 1 Halt Status
E 1 Carry Bit
SC 3 Sequence Counter

And the table of instructions it supports is:

Symbol Hexcode Description

I = 0 I = 1
AND 0xxx 8xxx AND memory word to AC
ADD 1xxx 9xxx Add memory word to AC
LDA 2xxx Axxx Load AC from memory
STA 3xxx Bxxx Store content of AC into memory
BUN 4xxx Cxxx Branch unconditionally
BSA 5xxx Dxxx Branch and save return address
ISZ 6xxx Exxx Increment and skip if zero
CLA 7800 Clear AC
CLE 7400 Clear E
CMA 7200 Complement AC
CME 7100 Complement E
CIR 7080 Circulate right AC and E
CIL 7040 Circulate left AC and E
INC 7020 Increment AC
SPA 7010 Skip next instruction if AC is positive
SNA 7008 Skip next instruction if AC is negative
SZA 7004 Skip next instruction if AC is zero
SZE 7002 Skip next instruction if E is zero
HLT 7001 Halt computer
I/O INP F800 Input character to AC
OUT F400 Output character from AC
SKI F200 Skip on input flag
SKO F100 Skip on output flag
ION F080 Interrupt on
IOF F040 Interrupt off

The assembler is a bit different than the book, it supports labels of any size and uses the character (:) instead of (,) also I added the LBL pseudo instruction that can help in some cases:

ORG N Hexadecimal number N is the memory location

for the instruction or operand listed in the following line
DEC N Signed decimal number N to be converted to the binary
HEX N Hexadecimal number N to be converted to the binary
LBL L Address of label L to be converted to the binary
End of symbolic program

There are 3 sample programs to select, or you can enter your own. After your program is ready press the [Assemble] button, if the program is correct you will need to load the binary codes of the program into memory, you can do this pressing the [Load] button. Now you are ready to run the whole program with [Run] or just go cycle by cycle with [Next].

The source is available under the MIT license in:

Have fun!


  1. A programmable, mechanical, digital machine
    Could carryout any calculation
    Could make decisions based upon the results of the previous calculation
    Components: input; memory; processor; output

  2. This comment has been removed by a blog administrator.

  3. muchas gracias! ha sido de gran ayuda!

  4. Excelente contenido, sigue actualizando asi!

  5. hi..Im student from Informatics engineering, this article is very informative, thanks for sharing :)

  6. Simulator has a bug with carry bit (E). When you try to add 5000H and 6000H, E is set to 1 instead of 0.


    ORG 100
    ADD A
    ADD B
    STA C
    A: HEX 5000
    B: HEX 6000
    C: HEX 0