∑niac II
The ∑niac II (pronounced "Zee-niac") is a minimal processor. There is only one user-accessible register, the accumulator A. The ∑niac operates on 8-bit words, and has a 5-bit address space. There are 6 regular instructions, as well as a special "halt" instruction that indicates the end of computation. Each instruction is encoded in one byte: 3 bits opcode, and 5 bits address. The 5-bit instruction counter IC (also called the program counter) is reset to 0 upon a reset, so that the instructions always start at address 0.
The memory is organized as follows:
ROM: addresses 0x00 .. 0x17 (24 bytes) - for program and constants
RAM: addresses 0x18 .. 0x1f (8 bytes) - for memory variables
∑niac II instruction set and opcodes
opcode | mnemonic | meaning | |
---|---|---|---|
0 | 000 aaaa | ld A, addr | A = Mem[addr] |
1 | 001 aaaa | sub A, addr | A=A - Mem[addr] |
2 | 010 aaaa | add A, addr | A=A + Mem[addr] |
3 | 011 aaaa | st A, addr | Mem[addr] = A |
4 | 100 aaaa | b A, addr | IC = addr (goto addr) |
5 | 101 aaaa | bneg A, addr | if A7 == 1, IC = addr (goto addr if A is negative) |
6 | |||
7 | 111 1111 | halt | stop execution |
The ∑niac II is a slight modification of the ∑niac, a computer designed by a group of students in a J-term course in 1999. It is small enough that its complete circuit can be constructed and simulated (which we will do later in the semester).
Sample programs
Here is a small program to compute 3+10-1 and store the result in RAM. Note that labels are used for all addresses.
address instruction opcode comments
hex binary label (mnemonic) binary hex
00 00000 ld A, C3 000 00101 0x05 // constant 3 is stored at address C3 == 5
01 00001 add A, C10 010 00110 0x46
02 00010 sub A, C1 001 00111 0x27
03 00011 st A, X 011 11000 0x78
04 00100 halt 111 11111 0xFF
05 00101 C3: 3 0000 0011 0x03
06 00110 C10: 10 0000 1010 0x0A
07 00111 C1: 1 0000 0001 0x01
18 11000 X: // variable X is stored in Ram at address 0x18
Here is a program to sum the numbers from 1 to N and load the result into the accumulator. Addresses are given in hex. Again, labels are used for all addresses (constants, variables, and branch targets)
address instruction opcode
00 ld A, N 000 01100 0x0C
01 st A, sum 011 11001 0x79
02 loop: sub A, C1 001 01011 0x2B
03 bneg end 101 01001 0xA9
04 st A, i 011 11000 0x78
05 add A, sum 010 11001 0x59
06 st A, sum 011 11001 0x79
07 ld A, i 000 11000 0x18
08 b loop 100 00010 0x82
09 end: ld A, sum 000 11001 0x19
0A halt 111 11111 0xFF
0B C1: 1 0000 0001 0x01
0C N: 5 0000 0101 0x05
18 i:
19 sum:
The actual ∑niac simulator only reads "machine code" (a column of hex values, one line per value), so my recommendation is to use a spreadsheet to write your programs in the form above. This makes it easy to just select the hex column and paste it into another document.