I'd like to write my own PIC compiler because there isn't one on the Macintosh OS X platform.
Can someone explain how to convert the machine code? Consider this example:
ORG H'0000'
BCF PORTA,0 BCF PORTA,1 BCF PORTA,2 BCF PORTA,3 BCF PORTA,4 BCF PORTA,5 BCF PORTA,6 BCF PORTA,7
END
If I compile the above thru an existing PC compiler I get a .hex file that looks like this:
:020000040000FA :10000000051085100511851105128512051385133C :00000001FF
The PIC manual tells me that these lines can be read like this:
:BBAAAATTHHHH....HHHCC where:
BB is a two digit hexadecimal byte count representing the number of data bytes that will appear on the line.
AAAA is a four digit hexadecimal address representing the starting address of the data record.
TT is a two digit record type record type that will always be '00' except for the end-of-file record, which will be '01'.
HH is a two digit hexadecimal data byte, presented in low-byte/high-byte combinations.
CC is a two digit hexadecimal checksum that is the two's complement of the sum of all preceding bytes in the record.
Now we know that the PIC 16F628 is a 14 bit device. So first question is, what do we do with the extra two bits that we get? What if we get one less than 14 bits?
According to the spec - the BCF instruction is the following format:
0100bbbfffffff where 0100 is the opcode, bbb is the bit #, fffffff is the file #.Looking at the first instruction, BCF PORTA,0 equates to machine code
0510. Converting that to binary I get 10100010000. This is not 14 bits so I assume padding with leading zeros. That makes it 00010100010000. Where's the 0100 opcode? As you can see from below, I have the same issues interpreting the other instructions. Some of them are more than 14 bits! Some of them are less!Also, why does the compiler use a 16 bit word for a 14 bit instruction? Why would it ever write out an 8510 which is a value greater than 14 bits?
0510 = XXXXX10100010000 8510 = 1000010100010000 0511 = XXXXX10100010001 8511 = 1000010100010001 0512 = XXXXX10100010010 8512 = 1000010100010010 0513 = XXXXX10100010011 8513 = 1000010100010011