Re: mixing C and assembly



Walter Banks wrote:
Mark Borgerson wrote:
Just out of curiosity, how do you set the initial value of the
stack pointer in C?

Most embedded systems compilers have extensions that
support processor register access.

Those I use don't, at least if you don't count inline assembler macros.

In our case the first C compiler was written for the C6805
and that was based on a 6805 mistral compiler we had written
a few years earlier. Our initial startup code was written
in C on a compiler that would support it.

register_sp SP;

SP = int_value;

What you're doing here is writing assembly with C syntax. It relies upon
a heavily non-standard language extension, and makes assumptions about
how the compiler behaves (you don't want the compiler to use the stack
before your SP assignment, do you?). So instead of writing assembly in
C, I prefer using the real thing.

But a program doesn't need much assembler code. Actually, one of my
recent ones has exactly two lines of assembler: the SP assignment,
followed by a call to 'main'. But, to be fair, this program is preceded
by a boot loader which is 90% assembler, and leaves the processor in a
sane state: annoying registers and BSS segment zeroed, compiler startup
code often assumes neither.


Stefan

.



Relevant Pages

  • Re: mixing C and assembly
    ... there are compiler extensions or assembly wrappers that link C functions to interrupts. ... Since you hang out gcc for not being "a full C implementation", and for having "extensions quite apart from extensions for the target", can you give me some examples of other available compilers that *are* "full C implementations", which have *no* compiler extensions, and which are targeted at embedded systems? ... The "C" function to set up the UART on an 8051 with a Keil compiler looks almost the same as assembler! ...
    (comp.arch.embedded)
  • Re: What micros do you actually hate to work with?
    ... with less than tiny asm ... hassle to work with 32 bit longs in assembler for an 8 bit uP, ... Microchip's C compiler tools and their assembly under MPLAB. ... is that other programmers for C are easier to find. ...
    (comp.arch.embedded)
  • Re: The Promise of Forth
    ... Declare variables, declare locals, let the compiler do the work ... Forth could be considered the assembler for a simplified virtual ... If you use locals then you have to initialise them each time. ... there are likely to be libraries that could be profitably used within ...
    (comp.lang.forth)
  • The never ending assembly vs. HLL war
    ... > branch instruction excluded is not particularly effective optimization. ... > CPU, chances are pretty good it *won't* be optimal on a different CPU. ... > discussing the futility of optimizing it in *assembler* when the ... careful and consider the code the compiler is emitting (and adjust your ...
    (comp.lang.asm.x86)
  • Re: the quality of assembly language code
    ... Intel's compiler is supposed to ... I have found that I prefer 'C' and assembler roughly in inverse ... >> code than human beings writing raw assembly language. ... > assembly programmers and compilers. ...
    (comp.lang.asm.x86)