From: GAMMELJL AT SLU DOT EDU Date: Mon, 31 Aug 1998 18:04:28 -0500 (CDT) Subject: passing arguments in registers To: djgpp AT delorie DOT com Message-id: <01J19GJU8Q9U94JXNE@SLU.EDU> Organization: SAINT LOUIS UNIVERSITY St. Louis, MO MIME-version: 1.0 Precedence: bulk The following C/C++ code when compiled: gxx example9.cc -S -O2 results in the .s file below it. It is plain that the arguments of zadd are passed on the stack. Eli Zareteskii has told me that passing them in registers requires __attribute__((regparm=2)) and that the information about this is in the GCC docs. Please: someone expert in searching these docs tell me exactly where this attribute statement goes in the C++ code below and exactly what the correct syntax is. ____________________The C/C++ source code_______________________________ extern zadd(int m,int n); ------>one wishes to place the attribute int i,j,k; statement in this subroutine either here or below. main() {i=2; ------> adds 2 and 3. j=3; k=zadd(i,j); return 0; } zadd(int m,int n) --------> one wishes to place the attriute statement {return m+n;} in this subroutine ____________________The .s file produced_________________________________ .file "example9.cc" gcc2_compiled.: ___gnu_compiled_cplusplus: .text .align 2 .globl _main _main: pushl %ebp movl %esp,%ebp call ___main movl $2,_i movl $3,_j pushl $3 -------------> here 2 and 3 are pushed to stack pushl $2 call _zadd__Fii ----------> zadd is called movl %eax,_k -----------> result returned in %eax xorl %eax,%eax leave ret .align 2 .globl _zadd__Fii _zadd__Fii: pushl %ebp ------> standard entry to assembly subroutine movl %esp,%ebp movl 8(%ebp),%eax ---------> arguments taken from stack addl 12(%ebp),%eax added, and return in %eax leave --------> standard exit from assembly ret routine .globl _i .data .align 2 _i: .space 4 .globl _j .align 2 _j: .space 4 .globl _k .align 2 _k: .space 4