Thu Jul 16 10:47:10 CEST 2009

PIC18 decoder

The way to approach this is to start with the smallest opcode field.
For PIC18 this is the top 4 bits of the 16 bit instruction word.
(Which becomes the top 3 in my representation, as bcf/bsf are modeled
as a single parameterized instruction to ease the optimization of
logic complement).
                                           ;; p: 0/1
 (bpf    (p f b a) "100p bbba ffff ffff")  ;; bsf/bcf
 (btfsp  (p f b a) "101p bbba ffff ffff")  ;; btfss/btfsc
 (btg    (f b a)   "0111 bbba ffff ffff")

The question is then: how to specify this as an equation
(bidirectional function) and how to attach semantics to the fields to
build the simulator.

Currently the letters used as parameter names have a semantics: this
should be defined better as connections to machine state (i.e. R means
PC-relative word addressed).  These should all be equations.

This really hints at the proper solution though: all this is so
intimately related that it should be solved as a whole.  It is really
not much more than a single morphism between the two spaces:

  ( machine-statevector, binary-instructions, computation-logic )

  ( msv-rep, highlevel-instruction-syntax, simulator-primitives)

The problem is representing all this in a form that is accessible for
metacomputation.  Maybe it's best to start with a ball-of-mud and
then disentangle it piece by piece?