function reCalcInst() { //alert("foo"); var inst = document.getElementById("op"); var bin = inst.options[inst.selectedIndex].value; var val = document.getElementById("val").value; // document.getElementById("opBin").nodeValue= //TODO conver bin to binary var instStr = reverse(pad(dec2bin(val),5)) + "0000000" +pad(dec2bin(bin),3)+ "0000000000000000"; document.getElementById("instBin").innerHTML = instStr; lightHtml = ""; for (i=0;i'; } else { lightHtml = lightHtml + '1'; } } document.getElementById("instPic").innerHTML = lightHtml; } function reverse(inp) { var outp = ""; for (i = 0; i <= inp.length; i++) { outp = inp.charAt (i) + outp; } return outp; } function light(i,val) { alert(i +" "+ val); } function dec2bin (val) { ans =""; while (val>=1) { quot = val % 2; val = Math.floor(val / 2); ans = (""+ quot) + (""+ans) ; //alert(ans); } //ans = ("p" + quot) +("" +val) ; //alert(ans); return ans; } function pad(val,length) { ans = val+""; leaders = length-val.length; for (i=leaders;i>0;i--) ans = "0"+(ans+""); return ans; } function nop() { return false; } EOT; include "header.php";?>

Instructing Baby

A computer program is list of very simple instructions, which is stored and obeyed in sequence. The computer will start at the beginning and continue through the list unless told to go to another instruction, known as a jump. Jumps may be to forward and backward, or conditional on the result of a calculation. These simple instructions can be used to create loops and other structures.

As well as instructions there is also data – the information the computer works with. In the case of the Baby, this was usually stored after the last instruction of the program.

The are just seven different instructions used when programming the Baby

*Addition was performed by subtracting a minus number e.g. 1+3 = 1- (-3)

Instruction Abbreviation number binary dot pattern
Jump to an instruction JMP 0 000 000
Skip some number of instructions JRP 1 001 001
Load LDN 2 010 010
Store STO 3 011 011
Subtract SUB 4 100 100
Subtract (same as above)   5 101 101
Skip if last result <0 CMP 6 110 110
Stop STP 7 111 111

line from baby's memory showing first 5 dots as data and 13th to 15 as instruction type

Each row in the Baby's memory contains just one instruction in the program. The 13th to 15th bits code the type of instruction (subtract, store etc.) with the first five bits coding additional information for that instruction (e.g. which line of memory that instruction should use). The remaining bits of the line can be used for any other purpose (e.g. storing data). If a line is not used to hold an instruction it can be used to store a 32-bit binary number (i.e. data to be used in the program).

The principle in programming modern computers is just the same, the only difference an increase in the number of different types of instructions. Multiplication, and division are examples of instructions now present in modern computers, as although the Baby could perform them by repeated subtraction (see first program below) it was a slow process.

The series of instructions had to be entered line by line, dot by dot. You can learn more about controlling the baby.