ttc.js

ttc.js

9cdd3562 simplified exam · by Franck Pommereau

The Tiny Computer

The Tiny Computer (TTC) is a virtual computer that comes with an assembler and an interactive simulator. It is used to teach computers architecture and most of the information is delivered during the lectures, so forgive the very sparse documentation on this page. This version is a complete rewrite of previous versions using Python/Brython so that it be executed entirely inside a Web browser.

TTC is a 16-bits machine with:

  • a RISC-like CPU with 16 registers (16-bits)
  • a RAM of 2¹⁶ 16-bits words
  • a ROM that is copied into the RAM during boot
  • a colour text screen
  • the 16 first words in memory form the interrupt table
    • RAM[i] contains the address for interrupt handler #i
    • interrupt #0 is the boot program
    • interrupt #1 is for CPU errors (invalid instruction, divide by zero)
    • interrupt #2 is for devices errors
    • interrupt #3 is the clock interrupt

The CPU registers and instructions are described in the editor/assembler GUI.

Editing and running 'Hello world!' example

Installation

To use TTC without installation, go to TTC open server.

If you wish to provide TTC on your own server, just git clone and copy Python module ttc (ie, directory ttc) to directory www. Then serve the content of www over HTTP, for instance running python -m http.server --directory=www.

Status

TTC development is in progress, expect bugs. Planned changes include:

  • add cache with parameterised strategy
  • add example programs

Usage

Root page is the editor and assembler GUI:

  • left-most column is the editor with buttons to
    • clear source code
    • undo/redo
    • download source code
  • middle column is the BIOS viewer, showing the result of assembler, with buttons to
    • assemble source code, each error encountered is displayed next to the line numbers in the editor (hover marks to see the error message)
    • start simulator (in a new tab/window, so popups must be allowed)
  • right-most column is a quick reference about the assembly language, with a button to point browser to the repository

When the simulator is started, a new tab/window opens with its GUI:

  • top toolbar allows to control the simulation with buttons to
    • execute one step of simulation
    • execute one CPU cycle (or finish current one)
    • start/stop automatic simulation
    • control automatic simulation speed
    • point browser to the repository
  • the state for the various elements of the computer is displayed into boxes. Displayed words will flash in green when they are read, and in red when they are written. The displayed elements are
    • CPU registers
    • CPU cycle progress
    • interrupt vector and mask (register MR)
    • bus
    • screen
    • RAM
  • RAM is displayed as a series of views, initially one with the interrupt table and another with the assembled program. New views can be added, with the right button next to title "RAM". RAM views consist of a toolbar and a scrollable text area showing part of the RAM state. The toolbar comprises:
    • an input to define the starting address of the view, and another for the ending address. These inputs can be edited directly or using up/down/pg-up/pg-down keys. Leaving the input or hitting the enter key validates the new limit and updates the view
    • a button to disassemble the RAM content, if some lines have been selected, only those lines are disassembled, otherwise, the whole view, restricted to the ROM content, is disassembled (note that disassembling the whole memory may take a long time)
    • buttons to scroll the view to IP/SP/BP addresses (disabled if not within the view's boundaries)
    • a button to remove the view

The simulator page must be loaded from the editor. Direct access to it will cause an error because it will lack the assembled BIOS to be loaded into the ROM. Reloading the page is okay and reboots the machine.

Licence

TTC is open source, released under the MIT Licence. See LICENCE.md.

TTC includes external libraries for an easier installation:

  • www/cm is CodeMirror source code editor
    • file www/cm/mode/ttc/ttc.js has been added to colour assembly source code, and it is part of TTC
    • CodeMirror is released under the MIT Licence, see www/cm/LICENCE
  • www/mdi is Material Design Icons icons set
    • Material Design Icons is released under the Pictogrammers Free License, see www/mdi/LICENCE
  • www/brython.js, www/brython_stdlib.js, and www/unicode.txt are Brython runtime

Author

TTC has been developed by Franck Pommereau.