About Tiny Computer
A small, made-up computer you can watch working. Write a program on the coding form in its assembly language (or pick one of the examples), then press STEP to carry out one instruction at a time, or RUN to let it go at the speed you choose. The line it will carry out next is highlighted on the form. The front panel shows everything inside the machine: the four registers and the program counter as rows of lamps, the flags, and all 256 bytes of memory, which light up amber when an instruction reads them and red when it writes them. OUT and OUTC type on the teleprinter; IN reads the eight data switches. INSTRUCTIONS on the form lists everything it understands.
Keys (when you're not typing in the form): Space runs or stops, S steps, R resets. In the form, Ctrl+Enter runs. Tab to the memory and the arrow keys read each byte. Your own program is kept in this browser (pick Your program to get it back), and COPY LINK copies a link that opens it, for sending to someone else.
MACHINE CODE AND ASSEMBLY
A processor only ever obeys numbers. Each instruction is a number (the opcode) followed by the numbers it works on, all sitting in memory beside the data: this is machine code. Writing it by hand means remembering that, on this machine, 3 0 7 means "put 7 into register A". Assembly language gives every instruction a short name (MOV A, 7) and lets you name places in memory with labels (loop:), and a program called an assembler turns the names into the numbers. One line of assembly is one machine instruction, so you're still telling the machine exactly what to do, step by step. The second column on the form, beside the line numbers, is the assembler's listing: the address where each line landed and the bytes it became.
THE STORY
The first stored-program computers were programmed in numbers. EDSAC, built at Cambridge University's Mathematical Laboratory, ran its first program on 6 May 1949, and already did better: its "initial orders", written by David Wheeler and kept on telephone-exchange switches, were copied into memory when the machine started, and read the program from paper tape, turning each instruction written as a letter and a decimal address into binary as it loaded. In effect, a tiny assembler. Wheeler also came up with the subroutine call that jumps away and comes back (here, CALL and RET). In 1951 Maurice Wilkes, Wheeler and Stanley Gill published their library of subroutines and how to use it, the first book on programming.
Kathleen Booth, who worked with Andrew Booth on their ARC machines at Birkbeck College, London, set out a written notation for instructions in the 1947 report Coding for A.R.C., written during a visit to Princeton, and is credited with the first assembly language. Through the 1960s and 70s, minicomputers had front panels like this one: rows of lamps showing the registers, and switches for putting numbers straight into memory. A computer that had lost its program was started by toggling a short loader in on the switches, one word at a time.
This app grew from the Python script assembler.py, an interpreter for a small language in the style of Intel assembly, with four registers (eax to edx), mov, add, push, labels, subroutines and an int 0x80 call borrowed from Linux for printing. Its example "The Python original" is here too; one of its subroutines is called _cube but in fact multiplies by three. That script runs the text directly; this machine assembles it into real bytes first, so the program sits in memory you can see, and the stack shares memory with it.
HOW IT WORKS
Everything is a byte: 0 to 255. A sum past 255 wraps round to 0 and sets the C (carry) flag; a subtraction below 0 wraps to 255 and sets C as well. Z is set when a result is zero. CMP A, B subtracts without keeping the answer, just to set the flags, and the jumps read them: JE jumps if Z, JL if C (A was less), JG if neither. Numbers are unsigned, so −1 is 255.
The assembler makes two passes over the form, as real ones do: the first works out how many bytes each line needs and so where every label lands; the second writes the bytes. The machine then repeats one cycle: fetch the byte at the program counter (PC), decode which instruction it is, fetch its operands, carry it out, and move PC on (or jump). The stack starts at the top of memory (address 255) and grows down: PUSH and CALL store a byte where SP points and move SP down one; POP and RET move it back up. Memory is shown in hexadecimal (base 16, two digits a byte) or decimal.
A run pauses by itself after 100,000 instructions (press RESUME to carry on; PAUSE stops it where it is too), in case a program loops for ever; left running with nobody using the page, it pauses after 5 minutes. Nothing you write leaves this page.
FURTHER WATCHING AND READING