Steve's 'Logical instruction set' (macro include file) for the PIC 8bit instruction sets
To protect the sanity of programmers in the western world (who read left to right, source to destination), here's my new PIC-33 (12F/16F5x) instruction set (RIGHT click and 'Save As') include file
The BIG advantage of using your own instruction set is that you can build the macro to take advantage of whatever 'version' of the PIC CPU you intend to use, i.e. those with the 'baseline' 12bit 33/35 instruction set, or the 'mid range' 14bit or 'enhanced' 14bit instruction set CPU
WARNING = ALL my assembler mnemonics stick with the 'normal convention' of "ACTION Source, Destination".
I consider this quite vital, as any 'exceptions' will not only confuse you later but will inevitably lead you into getting the 'order' wrong for the 'non-exception' cases ...
To avoid confusion, SUBtract (SUB a,b) 'means' subtract the source from the destination (so SUB 1,Acc means decrement the Accumulator), and SUB reg1,reg2 will be resolved as reg2 = reg2-reg1 To 'set' bit3 in regN, the code is "BSET regN,b3" (note, "BSET regN,3" might 'work' but (in general) my macro's expect parameters to be passed as names (so they can be set and reset) Conditional Jump (and Call) is a bit more complex, however just remember it's 'source' (in this case what to test eg. reg,bit) followed by 'destination' (the address to jump to). Both 'bit X' (b0-b7 '1') and 'not bit X' (nb0-nb7 '0') are supported = for example "BRA Acc,nb7,labelX" = Branch if Acc bit7 is 'not' set (nb7) to labelX. In addition to bX and nbX, 'Z' (and nZ) are accepted, so, for example, "CALL regX,Z,labelY" = CALL when regX is zero).
Some instructions have multiple names = for example I'm always forgetting if it's 'JMP', 'JUMP' or 'BRAnch' - so I just wrote one conditional BRAnch macro and have the JMP and JUMP macros re-directed to JMP. I also can't be bothered top rem,ember it's LOAD immediate and COPY for other cases (so COPY supports LOAD immediate as well)
'Acc' means the Accumulator (in 'PIC speak' that's the 'W register') and defaults to the value 0x00.
INDF, the 'indirect file pointer' defaults to 0x20 (it can't be 0x00 since I need that for the default Acc value)
The macro system can reSET all the register (and bit) name values so the macro IF (flow control) can 'spot' the difference between an 'immediate' value (0x00) and the Acc etc.
The PCL 'register' is the low byte of the program counter ('$'), which 'auto increments' as each instruction is executed. To DECrement the Acc, I use "ADD PCL, SUB PCL" (so result is Acc -1), and to INCrement the Acc, "SUB PCL, ADD PCL" (so Acc +1). This ONLY WORKS when $ is NOT ON A FF-00 boundary (the macro looks for this, but the MPASM 'Linker' can 'move' the assembled code later)
My MPASM macro 'include' (text) file may be downloaded from the link above. The exact same the file contents is displayed below :-
Next page :- PIC overclocking