GCC4でARMのインラインアセンブラ


**** c ****
int add (int x, int y) 
{ 
  return x + y; 
}

**** asm ****
        .align 2
        .globl _add
_add:
        @ args = 0, pretend = 0, frame = 8
        @ frame_needed = 1, uses_anonymous_args = 0
        stmfd   sp!, {r7, lr}
        add     r7, sp, #0
        sub     sp, sp, #8
        str     r0, [sp, #4]
        str     r1, [sp, #0]
        ldr     r2, [sp, #4]
        ldr     r3, [sp, #0]
        add     r3, r2, r3
        mov     r0, r3
        sub     sp, r7, #0
        ldmfd   sp!, {r7, pc}

**** c ****
int addasm (int x, int y)
{
  int res;
  asm("\n"
    "   @ gcc inline assembly\n"
    "   add     r3, r1, r0\n"
    "   str     r3, [sp, #8]\n"
  );
  return res;
}
	                
**** asm ****
        .align 2
        .globl _addasm
_addasm:
        @ args = 0, pretend = 0, frame = 12
        @ frame_needed = 1, uses_anonymous_args = 0
        stmfd   sp!, {r7, lr}
        add     r7, sp, #0
        sub     sp, sp, #12
        str     r0, [sp, #4]
        str     r1, [sp, #0]

        @ gcc inline assembly
        add     r3, r1, r0
        str     r3, [sp, #8]

        ldr     r3, [sp, #8]
        mov     r0, r3
        sub     sp, r7, #0
        ldmfd   sp!, {r7, pc}
Copyright (C) 2008 Hiroki Mori All Rights Reserved.