Simple-As-Possible Computer (SAP-1) simulator

(Castellano) (Català)

On this website you can find a Simple-As-Possible Computer version 1 (SAP-1) simulator, proposed by Albert Paul Malvino and Jerald A. Brown in their book «Digital Computer Electronics» (McGraw-Hill Education Editorial).

The animation was created for teaching and educative purposes with Processing and published on this website by means of Processing.js library for the subject «Computers Fundamentals» of the Degree in Computer Science of  Rey Juan Carlos University. It is also used regularly for popular science activities such as the Science Week and for workshops on introduction to Computer Architecture.


SAP-1 is a computer with a bus-based architecture. It contains the following elements:

  • 8-bit multiplexed data/address bus.
  • 4/8-bit edge-triggered registers. The registers than can write to the bus contain an internal tristate buffer. Those that cannot do not have this buffer. The registers are:
    • Program counter (PC).
    • Input and memory address register (MAR).
    • Instruction register (IR).
    • Accumulator (A).
    • B register.
    • Output register (OUT).
  • Random-Access Memory (RAM) for reading/writing operations of size 16×8 bits (16 8-bit positions each). It is unified for data and programs.
  • Arithmetic-Logic Unit (ALU) with two operations (addition and subtraction) for 8-bit two’s complement data (ranging from -128 to +127, both included).
  • LED display for visualizing the data stored in the OUT register. In this simulator, we show directly the value corresponding to this display in decimal format.
  • Control unit (CU), of type controller-sequencer.

Main characteristics of SAP-1:

  • Accumulator-based machine, with two specific-purpose registers (B and output registers).
  • Reduced instruction set (LDA, ADD, SUB, OUT, HLT).
  • ALU instructions (ADD/SUB) perform 2-operand operations, where one operand (the accumulator) is both source and destination. The ALU word is 8 bits wide.
  • Addressing modes: absolute and implied.
  • The numeric data are interpreted in two’s complement to allow subtraction.
  • Multiplexed bus, this is, it transmits alternatively data or addresses. Its size is 8 bits, although the address are only 4 bits wide.
  • 16-byte unified memory for data and programs (von Neumann architecture). By default the program starts at the address 0.
  • 8-bit instruction format (4 bits for the operation code + 4 bits for the operand’s address, if any).
  • The instructions need several cycles to execute (multicycle datapath). The control unit can be built hardwired or with microprogramming. In this second case, we need two auxiliary ROM memories.

Program by default:

The simulator brings a preloaded program by default which is the one mentioned in the example 10-3 on page 145 of Malvino and Brown’s book. This assembly program is:

ADD 10
ADD 11
SUB 12

Each of these instructions ocupies 1 byte in memory. The first instruction of the program is stored in the address 0 of the RAM memory. All the program instructions are stored in consecutive addresses, without blank spaces. As this program has 6 instructions, the last one is stored in the address 5. On the other hand, in the memory addresses 9, 10, 11 and 12 you can find numeric data 16, 20, 24 and 32. The remainder addresses are not allocated and are not used in this program.

SAP-1 assembly instructions have a mnemonic, which is a sequence of 3 letters that allows distinguishing one instruction from the others. This mnemonic corresponds with the opcode (operation code), which are the 4 most significant bits of the instruction in machine language (binary) and which are provided by the instruction register (IR) to the control unit (CU).

The instructions LDA, ADD and SUB are followed by a numeric operand (from 0 to 15 in assembly, or the 4 least significant bits in the binary instruction). It is the memory address which stores the data we want to work with (absolute addressing). In these instructions there is always an implied second operand, this is, which is not explicitly indicated in assembly but that is used in the operation. It corresponds to the accumulator register (A), which saves the result of the last operation.

The instructions OUT and HLT do not have operands in assembly. OUT used as implied operands the accumulator (A) and the output register (OUT). HLT does not used any operand at all, as its function is to tell the simulator to end the execution.

All the instructions have the program counter (PC) as an implied operand, as it is incremented by 1 so that it points to the following instruction.

What does this program do? Very simple.

  • All the SAP-1 registers, including the accumulator (A), are reset to 0 at the start of the simulation. The instruction LDA 9 looks for a data which is stored in the memory address 9 and writes it in A. As in this address we have the number 16, A stores this value (in binary 00010000).
  • The instruction ADD 10 looks for a data which is stored in the memory address 10 (and that contains the value 20) and adds it to the accumulator (16). The result (36) is stored again in A (36 in binary is 00100100).
  • The instruction ADD 11 looks for a data which is stored in the memory address 11 (its value is 24) and adds it to A (36). The result (60) is stored again in A (60 in binary is 00111100).
  • The instruction SUB 12 looks for a data which is stored in the memory address 12 (value 32) and subtracts it from the value stored in A (60). The result (28) is stored again in A (28 in binary is 00011100).
  • The instruction OUT reads the value of the accumulator and sends it to the OUT register. Therefore, the value in  OUT is now 28 (000111000).
  • Last, the instruction HLT stops the simulator. In order to execute the program again, or if you want to modify it, you have to click the «Restart» button.

Functioning of the simulator:

  • All the interactive parts are coloured in yellow and underlined and change their colour when the mouse pointer hovers over them. The disabled parts are drawn in grey.
  • Just after loading the page there is a welcome window. Click the «OK» button in order to make it disappear.
  • The internal structure of SAP-1 is shown afterwards. The only interactive elements allowed are the RAM memory and the scrollbar that controls the animation speed.
  • First of all, you have to load a program into memory. To do so, click on the RAM memory. A new screen with the current contents of the memory will be shown, which is initially blank (all the bits are 0). By clicking on any of the 16 memory addresses, the contents is «disassembled», this is, the stored value is reinterpreted as if it is an instruction or a data. You can also modify this memory address to write an instruction or a data. On other hand, we can also load the default program. If you want to reset the memory and empty its contents, click the «Erase program» button. In order to go back to the simulator main screen, click the «Back» button. Notice that the simulation will not be able to start until a program has been loaded into memory.
  • Back again to the main screen, there are two options to start the simulator. On the one hand, you can click the «Play» button (right-pointing triangle), located at the bottom left part of the screen. From this moment the clock (CLK) starts working and the execution of the program loaded in memory begins. The programs runs all over the way. With the simulation on, the «Play» button changes into a pause button. You can pause the simulation and resume it as many times as you wish. On the other hand, there is a «Play 1/2 CLK» button, which is only available when the simulator is in pause mode. When clicking this button, you can only advance half a clock cycle in the program execution, which is very useful to study in detail the sequence of steps going on.
  • At any time and without needing to pause the simulator, you can modify the speed of the program execution by means of the scrollbar located at the bottom right part of the screen. The more to the right the bar is, the faster the execution will be.
  • If you want to restart the simulation from the very beginning, just click the «Restart» button (two left-pointing triangles). Notice that you can only click it when the simulation is in pause mode. Restarting the simulator does not erase the program loaded in memory. If you can modify it, you can click again on the RAM memory.
  • During the program execution, you can see at the top right part of the screen the control word generated by the control unit. These signals are activated or deactivated at specific moments to perform the correct execution of programs.
  • In the centre of the screen you can see the 8-bit bus. Black colour means the low value of voltage (0 volts) or logic 0; red colour is used for the high value of voltage (5 volts) or logic 1; last, grey colour represents the high impedance state (disconnection or null electric current), which is produced when no computer component is writing to the bus.
  • During any of the steps in which the execution of the program is divided, the active elements are shown in white colour, while the inactive ones are in grey colour. It has to be understood that an element is active when it is writing a valour to the bus or reading a value from it, o when it is performing some internal operation.
  • The program execution continues automatically until the HLT (halt) instruction is reached in the program, or, if a non-valid operation code is found. In order to begin the execution again, you have to click the «Restart» button.

Back to animation index (in Spanish)

Comentarios cerrados.