ByteCraft COP8C Compiler | |
General compiler notes |
|
BITS and CHAR |
/*The use of
CHAR to define an unsigned int8 is OK, but BITS allows you to take easy
advantage of the bit test capability of the COP8. Bit postionions
can then be specified on the fly instead of defining a bit with a
variable*/ UNSIGNED BITS test_data; if (test_data.0) //if lsb=1 then... { //code } UNSIGNED INT8 test_dat BIT test_dat0 @ test_dat.0; if (test_dat0) //if lsb=1 then... { //code } |
For-Next Loops |
/*The compiler
does not handle loops very efficiently, even when using the faster
registers from 0xF0-0xFB. The DRSZ opcode is never used for a loop
that terminates after zero is hit but a bit of inline assembly can fix
that... saves about 10 instructions*/ #DEFINE loop_counter_a 0xF8 //need this for DRSZ to compile correctly this_is_loop: //loop code #asm "DRSZ loop_counter_a" #asm "JP this_is_loop" |
#DEFINE | Don't put a comment right next to the last character of a #DEFINE parameter. The parser needs a space because a "\\" will be interpreted as part of the parameter, generating a random error. |
INT8 vs CHAR |
/*The use of "i>0" in the loop and "INT8 i;" for the variable declaration
will make the compiler do the end of loop test as a signed integer which
will require two tests instead of just one. Use unsigned int8 to be
absolutely sure*/ CHAR i; For (i=8;i!=0;i--) { //CODE } |
STOP | If the linker ever sees the word "STOP" in upper case and preceeded by one or more spaces, it will litterally choke on it and fail the linking process. If in lower case, or just after any other charater than a space and the linker won't see it. The error code is "UNKNOWN" so it's not clear why it does not like it! |
NOINIT |
/*The compiler can be
made to skip the creation on initialization code, at 0x0000 by putting the
following directive at the beginning of the source code, before any
functions are defined:*/ #pragma option NOINIT; /*Your own reset code then follows...*/ #asm //starts code at reset vector ORG 0 ;Start at 0000 #endasm void reset(void){ PSW.GIE = 0; //interrupts off SP = 0x6F; //stack, must agree with compiler //more C code here! #asm JMP main ;Jump to main() #endasm } //Alternatively, but seems less relaible in this compiler... void reset(void) @ 0x0000; plus "void reset(void){ //------------------------------------------------------------------------------ void reset(void){ PSW.GIE = 0; //interrupts off SP = 0x6F; //stack, must agree with compiler //more C code here! //------------------------------------------------------------------------------ #asm JMP main ;Jump to main() #endasm } |
Low level initialization |
|
__STARTUP | If the compiler finds a function called
exactly "__STARTUP" during compile time, it will modify it's code to
include a call to this function after reset. There must be an actual
function, not just a prototype of the function for the compiler to
recognize it. The jump table for this function will be after the
last byte of ROM code used... If __STARTUP( ) function, the compiler will do the following: 0000 DD 6F LD SP,#06F ;setup stack pointer 0002 AC 02 00 JMPL 00200 ;jump to function main() ... __MAIN: 0200 ... ;standard location of function main()
If __STARTUP( ) is found,
and no ROM constant data is found, the compiler will do the following: |
Any questions or comments?
This page last updated on
September 04, 2011