# PROGRAMMING

We will now consider how to program a 16-bit, rather than 4-bit, computer.

A 16-bit computer has 16 bits in each 'word' and 65536 words of memory. This is because there are 65536 possible 16-bit addresses: 0000000000000000, 0000000000000001, 0000000000000010, 0000000000000011, 0000000000000100, etc.

The instruction still consists of four words, but now each instruction is 16 bits long. An example instruction is:

``` label       address             data          comment

instr_1  0000000000000100  0000000000000001  from address
0000000000000101  0000000000000010  to address
0000000000000110  0000000011111111  'to' bits to copy to
0000000000000111  0000000000100000  instr.addr.and rot.amount
```

The labels and comments are not part of the program. The addresses just show where the data is stored. The data is the program. An instruction written with instructions that are just 1's and 0's is a machine language instruction. Machine language instructions are called 'machine code.'

'Instr.addr.and rot.amount' is short for 'next instruction's address and rotate amount.'

Notice that there are now four (italic) rotate bits (0000). They cause the copied-from data to be rotated according to the following table.

## 16-Bit Rotate Table

```    rotate                         rotate    rotate
bit             16             left     right
values          bits           amount    amount

0000     ABCDEFGHIJKLMNOP        0         0
0001     BCDEFGHIJKLMNOPA        1        15
0010     CDEFGHIJKLMNOPAB        2        14
0011     DEFGHIJKLMNOPABC        3        13
0100     EFGHIJKLMNOPABCD        4        12
0101     FGHIJKLMNOPABCDE        5        11
0110     GHIJKLMNOPABCDEF        6        10
0111     HIJKLMNOPABCDEFG        7         9
1000     IJKLMNOPABCDEFGH        8         8
1001     JKLMNOPABCDEFGHI        9         7
1010     KLMNOPABCDEFGHIJ       10         6
1011     LMNOPABCDEFGHIJK       11         5
1100     MNOPABCDEFGHIJKL       12         4
1101     NOPABCDEFGHIJKLM       13         3
1110     OPABCDEFGHIJKLMN       14         2
1111     PABCDEFGHIJKLMNO       15         1
```

The bits to the left of the rotate bits in latch 0000000000000111 are 000000000010 and indicate that the next instruction will be in latches 0000000000001000, 0000000000001001, 0000000000001010, and 0000000000001011.

Latch 0000000000000100 holds 0000000000000001, so data is copied from latch 0000000000000001.

Latch 0000000000000101 holds 0000000000000010, so data is copied to latch 0000000000000010.

Latch 0000000000000110 holds 0000000011111111, so the rightmost 8 bits of the 'to' latch are copied to.

Page 25

Page 24 . . . Page 1 . . . Page 26