UMBC CMSC 391 -- Programming Microcontrollers  


C Programming

Everything is exactly the same, only different:

Sample

sample.c

Let's compile it with the following command:

make -f sampleMakefile (I had to use the -f option because I had another Makefile in the same directory!) That produces the following files:

sample.asm
sample.c
sample.ihx
sample.lnk
sample.lst
sample.map
sample.rel
sample.rst
sample.sym

Example

C/Assembly Language

You can combine C and assembly language, but, referencing things in between the two can be a challenge:
void main( void )
{
        idata int x;

        _asm
                inc x
        _endasm;
}

The reason why

The compiler mangles the variable names. To begin with, an underscore is prefixed to the global variable name. Local variables hae an underscore, the function name, and another underscore prefixed to the variable name, with more characters appended to the name. (I did not find any documentation for what those characters represent.)
;------------------------------------------------------------
;Allocation info for local variables in function 'main'
;------------------------------------------------------------
;x                         Allocated to in memory with name '_main_x_1_1'
;       asm.c 2
;       -----------------------------------------
;        function main
;       -----------------------------------------
_main:
        ar2 = 0x02
        ar3 = 0x03
        ar4 = 0x04
        ar5 = 0x05
        ar6 = 0x06
        ar7 = 0x07
        ar0 = 0x00
        ar1 = 0x01
;       asm.c 8
;       genInline
                        inc x


©2004, Gary L. Burt