Beware: This is a work in progress as of 2023-05-01. If you have suggestions, I'd like to hear about them.
Welcome to TBC!
TBC is the "Tiny Binary Computer." It was inspired by the Little Man Computer, devised by Dr. Stuart E. Madnick of MIT. TBC uses the same instructions as the Little Man Computer, so programs written for LMC can be assembled and run on TBC with only very minor changes.
However, the Tiny Binary Computer is different from the Little Man Computer in a number of important ways. Perhaps the most important is that TBC, like all modern computers, is a binary computer, not a decimal computer. The memory in TBC is organized into 12 bit words, with numbers stored as two's complement integers. That means TBC can store values from -2048 to +2047.
Another very visible difference is that there's no "little man." The instruction decoder (I-Decoder) and control unit perform the functions of the little man. The little man could remember memory addresses and their contents, and whether the calculator held a zero or positive number. In TBC, the memory address register (MAR), memory data register (MDR), and P/Z latch perform these functions. Instead of having the little man remember the current instruction, TBC stores it in the instruction register (IR).
Ready to Go?
TBC can save programs in your browser's local storage. If you're ready to try things out, here's a sample program. It's the "positive difference" program used in many LMC examples. Like a real computer, TBC cannot process human-readable programs directly. They have to be translated by the assembler program into binary. To try out the sample program:
- Click the "Save" button just below the program; the sample program will be saved in your browser's local storage as "posdiff."
- Switch to the "Assembler" tab, use the drop-down menu to select the "posdiff" program and assemble it by clicking the "assemble" button.
- If all is well, the binary translation of the program will be saved, also as "posdiff" but tagged as a binary object program.
- Switch to the "Virtual Machine" tab, select "posdiff" and click "Load." The program is loaded into memory and the program counter is set to zero. Although the program is binary, it is shown as hexadecimal in the virtual machine for compactness.
- Click "Run" and the program executes. As with many real computers, each instruction takes more than one clock cycle. Provide an integer value at each of the two "Input?" prompts.
// Positive Difference Program // Reads two numbers and subtracts them. If the // difference is positive, it is printed. Otherwise, // the numbers are swapped and subtracted again, then printed. // You can think of the Accumulator as the display of a // very small calculator. // in read first number into Accumulator sto first store it in memory with name "first" in read second number sto second store it as "second" // The second number is stored, but also remains in Accumulator sub first subtract "first" from Accumulator brp print positive? print it (brp=branch on positive) lda first otherwise, load Accumulator with "first" sub second ... and subtract "second" print out send to output hlt and stop (hlt=halt) first dat 0x00 initializes "first" to zero... second dat // initialization isn't really necessary // because we will store a value here.
Register and memory contents: While a program is running on the virtual machine, you can place the mouse cursor over a register or memory cell to see the values in binary or decimal and how the cell would be interpreted as an instruction. It takes about a second for the tool-tip to appear.
Breakpoints: Clicking in a memory cell will set a breakpoint at that location. When it is about to be loaded, the clock will stop so that you can inspect the contents of memory and registers. Click "Run" or "Step" to continue. Step executes one instruction and stops again.
Saving the output: Click the "select all" icon on the lower right of the output screen, or click in the output screen and press control-A. Press control-C to copy the selected text to the clipboard.
Writing Your Own Programs
You can edit programs directly in the source window of the assembler panel, but you might find it easier to create programs in an editor application like Notepad++ and paste the source in the assembler window. You do need to save the source using the "Save as" because that's how the assembler knows what to name the translated binary program, also called the object program.
Because a browser's local storage is isolated from the rest of a computer's file system for security, the only way to get a source program back out of TBC is to copy it from the source window of the assembler and paste it into an editor program.
The operation codes (op codes) for TBC and their semantics are the same as those for the Little Man Computer, so any program written for LMC will work on TBC, too. The only difference is that, for TBC, there must be at least one space or tab before the operation code. Labels must begin at the left, with no preceding spaces or tabs. The details are in the documentation. The TBC assembler will try to reformat programs with the op codes at the left margin, but some manual corrections may still be necessary.
TBC makes extensive use of the features of HTML5 and CSS3. It won't work in older browsers, and will probably fail badly and in unexpected ways. TBC has been tested pretty thoroughly in Firefox 30 and somewhat less thoroughly in Chrome 35 and Internet Explorer 11. It ought to work in other modern browsers; if you have trouble, try Firefox or Chrome.
You can run TBC on a phone or tablet computer, but both the assembler and the virtual machine need lots of horizontal space. Using a desktop computer will probably be better.