/little-computer

The Little Computer

Primary LanguageRacketGNU General Public License v2.0GPL-2.0

DESCRIPTION

The Little Computer is a tool for creating computers. I have implemented it with the purpose of building the Hack Computer that is defined in the `TEoCS` book, “The Elements of Computing Systems”, MIT press, and taught in the course “From NAND to Tetris”.

The semantics of the Hardware Description Language that the Little Computer implemented is defined in the Appendix A of the TEoCS book.

The only difference between the semantics defined in the TEoCS and the current implementation is in Output. See the INPUT AND OUTPUT.

The development of the little computer took exactly 20 days of working a few hours each day. I built it after I discovered the Nand2Tetris course on coursera. In the first 3 weeks I quickly studied the materials and in the last 3 weeks I built the little computer.

INPUT AND OUTPUT

The output is different from the output defined in the TEoCS.

The Little Computer does not have a graphical output, it has only a simple console that can print ASCII characters only.

In the TEoCS implementation of the output one plots graphical pixels. To draw the pixel X,Y one needs to do so: SCREEN[X][Y]=1 (formula is abstracted modulo bus width).

In the Little Computer, in order to print the character with the ascii code A we do simply so: SCREEN[A]=1. The useful screen memory has only 128 locations. After such an assembler command is executed, at the next clock tick the action associated with the electric wire connected to the display will print the character.

This is the only semantic difference between the TEoCS definition and the current implementation.

Concerning the input, the operating system is supposed to provide the sound GETCHAR function that should be used by the programmer. The hack programmer who wants to read keys from the keyboard should know how the hack computer works in its internals in order to successfully write a getchar function. See the example code and the comments from `sim` in order to understand the logic behind.

THE LAYERS OF LANGUAGES

FILEIN-LANGOUT-LANGDESCRIPTION
*.hdlALGEBRAIC EQUATIONSHDLhardware description language
*.hdlHDLHDL BYTECODEsemantic check of hdl files
*.hwcHDL BYTECODEHWSmodularize the hardware structures
simHWS; HACK MICROCODEPROPAGATORSsimulator of the electrical signal flow
lexerREGEX COMBINATORS, RAW CODETOKEN STREAMtokenize an input in function of regexps
hack-lexicalREGULAR EXPRESSIONSREGEX COMBINATORSdefine hack token syntax
hack-phrase-structAUTOMATA, HACK TOKENSHACK MICROCODEcalled by hack assembler

HOW TO USE IT

1. compile the .hdl equations with

make hwc

This will create the .hw files in ./hw directory. One can split the whole computer in any modules we want by inserting them in MODULE-LIST. Each module in this list is compiled as a unit and can be either expanded in smaller atoms in the simulator or can be replaced by a software simulator within sim.

2. compile the hack programs with

make hack

This will create the binary files in Hack format in ./bin directory.

3. see the list of available hack programs doing so:

make sim

1.2.3.You can also execute all the steps 1-3 once just by typing:

make rebuild

4. execute the hack program `collatz` so:

make sim HACK=collatz

The Collatz program reads an integer from the input and displays the values of the collatz function.