Wednesday, 2 January 2013

Day 2 : CP1610 Definition File.

Waking up rather early this AM gave me the opportunity to write the 'generator' code for the processor.

This is a definition file for the processor which is run through a Python program which generates the actual code - rather than hand writing every opcode on its own.

It looks a bit like this (below). In a CP1610 each opcode is organised in groups of 8 (except for 000-007) so we can save on some cases by dividing the opcode by 8.

It is sort of code. The * is replaced by the lower 3 bits of the opcode, szWord is a 16 bit value used to track the current values of S and Z. Rather than actually setting the bits on every ALU operation we simply update this word, which works the same way. If I convert this to an Arduino or similar in 'C' these optimisations will speed things up signficantly.

000-007     if (* == 4) { jump(); } else carry = (* == 7) ? 1 : 0;    {} // Handles JUMP, SETC, CLRC

008-00F     szWord = reg[*] = (reg[*]+1) & 0xFFFF;                          {INCR R*}

010-017     szWord = reg[*] = (reg[*]-1) & 0xFFFF;                          {DECR R*}

018-01F     szWord = reg[*] = reg[*] ^ 0xFFFF;                              {COMR R*}

020-027     reg[*] = subCode(0,reg[*]);                                   {NEGR R*}

028-02F     reg[*] = addCode(reg[*],(carry != 0 ? 1 : 0));                {ADCR R*}

The whole thing is at http://www.robsons.org.uk/Gimini/cp1610.def

Tomorrow - write some unit tests.

No comments:

Post a Comment