Ram initialization and small c.

Jeremy Jackson jerj at coplanar.net
Tue Feb 25 10:54:01 CET 2003


Below is a trivial C program with a function call and a few loops.  When
compiled with gcc using the stated flags, it does not use any stack. 
The assembler output is below.

/* sample program demonstrating trivial C program */
/*  that doesn't use stack when compiled with gcc */

/* compile with gcc -O -fverbose-asm -fomit-frame-pointer -S -Winline  
*/
/*      -O optimization is required to honour inline keyword           
*/
/*         __attribute__((always_inline)); could be used if opt is bad 
*/
/*      -fverbose-asm helps when choosing compiler options             
*/
/*      -fomit-frame-pointer eliminates function prologue              
*/
/*      -S generates assembly, .c file becomes .s so you can inspect   
*/
/*      -Winline explains why if something can't be inlined            
*/

extern volatile int r; /* example MMIO register, could be an io insn
also */


static inline int afunc(const int x) {
        register int y;
        for (y=0; y<x; y++) {
                r=y;
        }
}

int main () {
        register int i,j;

        for (i=0; i<255; j+=i++) {
                afunc(j);
        }
        return(j);
}

-----------------------------------
        .file   "test.c"
        .version        "01.01"
# GNU C version 2.95.4 20011002 (Debian prerelease) (i386-linux)
compiled by GNU C version 2.95.4 20011002 (Debian prerelease).
# options passed:  -O -Winline -fomit-frame-pointer -fverbose-asm
# options enabled:  -fdefer-pop -fomit-frame-pointer -fthread-jumps
# -fpeephole -ffunction-cse -finline -fkeep-static-consts
# -fpcc-struct-return -fcommon -fverbose-asm -fgnu-linker
-fargument-alias
# -fident -m80387 -mhard-float -mno-soft-float -mieee-fp -mfp-ret-in-387
# -mschedule-prologue -mcpu=i386 -march=i386

gcc2_compiled.:
.text
        .align 4
.globl main
        .type    main, at function
main:
        xorl %ecx,%ecx
        .p2align 4,,7
.L12:
        xorl %edx,%edx
        cmpl %eax,%edx
        jge .L11
        .p2align 4,,7
.L15:
        movl %edx,r
        incl %edx
        cmpl %eax,%edx
        jl .L15
.L11:
        addl %ecx,%eax
        incl %ecx
        cmpl $254,%ecx
        jle .L12
        ret
.Lfe1:
        .size    main,.Lfe1-main
        .ident  "GCC: (GNU) 2.95.4 20011002 (Debian prerelease)"
---------------------------

On Wed, 2003-02-19 at 10:42, Ronald G. Minnich wrote:

> I have been on the hunt for small c-like compilers. I have yet to find one 
> that runs in the registers only, i.e. has an addressable memory of 16 
> words. 
> 
> My concern about a full-blown c compiler is this: we are going to move
> from debugging 1000 or so lines of assembly to debugging the compiler, and
> shipping a full compiler with linuxbios, just to eliminate this 1000 or so
> lines of assembly. It seems hard to justify. Since we will be the probable
> only users of this compiler the support burden will fall on us. There are
> not that many people out there needing a compiler that does this "your
> memory is only your register set" capability.
> 

-- 
Jeremy Jackson <jerj at coplanar.net>




More information about the coreboot mailing list