Re: mixing C and assembly
- From: Stefan Reuther <stefan.news@xxxxxxxx>
- Date: Wed, 23 Apr 2008 19:16:41 +0200
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
.
- Follow-Ups:
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- References:
- mixing C and assembly
- From: Lax
- Re: mixing C and assembly
- From: Hans-Bernhard Bröker
- Re: mixing C and assembly
- From: Chris H
- Re: mixing C and assembly
- From: Walter Banks
- Re: mixing C and assembly
- From: Mark Borgerson
- Re: mixing C and assembly
- From: Walter Banks
- mixing C and assembly
- Prev by Date: Re: TFT contrast problem
- Next by Date: Re: Getting fit with embedded systems
- Previous by thread: Re: mixing C and assembly
- Next by thread: Re: mixing C and assembly
- Index(es):
Relevant Pages
|