mixing C and assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mixing C and assembly

5,075 Views
irob
Contributor V
Working off of my previous thread, I'm in the process of integrating C and assembly. Referring to tech note TN 15 "Mixing Assembly and ANSCI C in an Application"

reference files:
* Freescale forums thread

* ftp3.metrowerks.com/pub/dropzone/Mixing_C_and_ASM.zip

Anyway, I've copied the code out of AN1831 and using TN15, I've added some external symbol definitions/references (XREF and XDEF). I also added the assembly include file for my MCU, located by default here:

C:\Program Files\Freescale\CW08 V5.0\lib\hc08c\device\asm_include\*.inc

What I found was that the AN1831 code has some strange errors in it. For instance there are periods following all the ORA opcodes. That doesn't compile (at least on the CW5 assembler), Then there's a byte called TESTMOD with no definition anywhere. Here is the snippet:

IFEQ TESTMOD
LDA FLBPR
LDA ,X
ENDIF
IFNE TESTMOD

So what is the value of "TESTMOD"?

Also, I'm getting the error "A13003: Value is truncated to one byte" on three out of four total BRCLR lines. Example:

BRCLR FLCR_MASS_MASK,CTRLBYT,PGSTUP

I can't find any significant differences between these four BRCLR instances, including how far they branch (2-3 lines at the most).

Finally, for some reason some of the labels are followed by a colon and some are not. For example:

AMBS: STA FLCR

...or:

NOBLWR STA ,X

The compiler doesn't seem to care, but is this a problem?
Labels (1)
0 Kudos
Reply
5 Replies

868 Views
bigmac
Specialist III
Hello iRob,
 
The original AN1831 code was written for MCUEZ assembler.  I have previously adapted the code so it should correctly assemble using CW 5.0 assembler (absolute assembly).  Note that a few simple macros are used as an attempt to make the code more understandable - some of these are defined in a separate file.  They include manipulations of a single bit within the accumulator.
 
Regards,
Mac
 
0 Kudos
Reply

868 Views
tonyp
Senior Contributor II
By the way, the macros PSHXH and PULHX although defined according to their names, are not correct since they actually push and pull in the same order for both.  Quote from 908macros.inc:
 
 IFNDEF  _PSHXH
_PSHXH:   ; PUSH X & H TO STACK
PSHXH:    MACRO
         PSHX
         PSHH
         ENDM
 ENDIF
 IFNDEF  _PULHX
_PULHX:   ; PULL H & X FROM STACK
PULHX:    MACRO
         PULX
         PULH
         ENDM
 ENDIF

Shouldn't they be PSHHX and PULHX?  They are used several times in the code, and I'm surprised if this code actually works for it keeps messing up the HX register with every PSHXH/PULHX pair (unless this happens at irrelevant instances, or HX isn't used between two such errors so HX is restored, didn't dive into it)!
0 Kudos
Reply

868 Views
bigmac
Specialist III
Hello tonyp,
 
Thank you for pointing out the error in the PULHX macro.  This was my oversight.
 
Regards,
Mac
 
0 Kudos
Reply

868 Views
tonyp
Senior Contributor II
It seems that TESTMOD is probably used for conditional assembly of code sections.  You must define it somewhere before it is encountered for the first time (perhaps even with a command-line option), with either zero (usually to indicate condition-is-off) or non-zero, but it really depends on the programmer's perception of true or false.  Personally, I prefer the more obvious
 
#ifdef somevar
#else
#endif
 
variant found in some assemblers so that an undefined symbol clearly relates to unused code, rather than trying to remember which value of an always-defined symbol to use for true or false (e.g., C coders may see no problem with this as it resembles C's convention of 0 being false, anything else being true, but this is not a universal convention, so for one who hasn't messed exclusively with C, using zero/non-zero for false/true usually doesn't feel very natural!).
 
Regarding the BRCLR errors, don't forget Bit-Test-And-Branch instructions on the HC[S]08 work only in direct addressing mode, and can only check one bit at a time (unlike the HC11's, for example, which can test multiple bits, and in any indexed location).  If the registers or variables you're checking with them are not in page zero, you can't use them.  Use LDA/BIT #mask/BEQ sequences instead.  Without knowing the addresses of the variables you use, I can only assume this is your problem.
 
Finally, single colons in the end of labels are normally ignored by most assemblers.  With some assemblers, they are used for marking global labels (while others use double colon for that), and it all really depends on the particular assembler's syntax.  You probably need to read the specific assembler's syntax specification once again.
 
Hope this helps.
0 Kudos
Reply

868 Views
Alban
Senior Contributor II
Tony, iRob,
 
TESTMOD is for Test Mode purposes and is not available in any way to the user.
You can remove references to it as you will not get information on this mode.
 
Alban.
0 Kudos
Reply