寄り道
http://twitter.com/natsutan/statuses/854451215
cdecl とかだと EBX は破壊できないので、普通は3つまでしか使えないんじゃないかなあと思います。規約違ったり RISC だったりするとそうでもないんですかねえ。 RISC よく知らないけど何かレジスタたくさんあるんですよね!
GNU 拡張使ってレジスタも使って引数渡すようにしてみました。
niha@hoge:~/src/c$ cat bin04.c __attribute__((regparm(3))) int hoge(int a, int b, int c, int d){ return a+b+c+d; } niha@hoge:~/src/c$ gcc -c -g -O bin04.c niha@hoge:~/src/c$ objdump -S bin04.o bin04.o: file format elf32-i386 Disassembly of section .text: 00000000 <hoge>: __attribute__((regparm(3))) int hoge(int a, int b, int c, int d){ 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 01 c2 add %eax,%edx 5: 01 ca add %ecx,%edx 7: 89 d0 mov %edx,%eax 9: 03 45 08 add 0x8(%ebp),%eax return a+b+c+d; } c: 5d pop %ebp d: c3 ret
というような。