リスト32 リスト33


〔リスト32〕広域レジスタ変数の定義を行った例のCソース(test102.c)
#include <stdio.h>
//広域レジスタ変数の定義
register int *foo1 asm ("ebx");
register int *foo2 asm ("edx");
int hensu[10] asm ("hensu_asm");
int tbl[10];
extern int  kansu (void) asm ("asm_kansu");
	
int main(void)
{
    *foo1   =   100;
    *foo2   =   200;
    hensu[0]    =   1;
    tbl[0]      =   kansu();
    return 0;
}
int kansu (void)
{
    return  *foo1 * *foo2;
}


〔リスト33〕広域レジスタ変数の定義を行った例のCソースから生成したアセンブラ(test102.s)
    .file       "test102.c"
    .version    "01.01"
gcc2_compiled.:
.text
    .align  4
.globl  main
    .type   main,@function
main:
    pushl   %ebp
    movl    %esp,%ebp
    subl    $8,%esp
    movl    $100,(%ebx)
    movl    $200,(%edx)
    movl    $1,hensu_asm
    call    asm_kansu
    movl    %eax,%eax
    movl    %eax,tbl
    xorl    %eax,%eax
    jmp     .L2
    .p2align    4,,7
.L2:
    movl    %ebp,%esp
    popl    %ebp
    ret
.Lfe1:
    .size   main,.Lfe1-main
    .align  4
.globl  asm_kansu
    .type   asm_kansu,@function
asm_kansu:
    pushl   %ebp
    movl    %esp,%ebp
    movl    (%ebx),%ecx
    imull   (%edx),%ecx
    movl    %ecx,%eax
    jmp .L3
    .p2align    4,,7
.L3:
    movl    %ebp,%esp
    popl    %ebp
    ret
.Lfe2:
    .size   asm_kansu,.Lfe2-asm_kansu
    .comm   hensu_asm,40,32
    .comm   tbl,40,32
    .ident  "GCC: (GNU) 2.95.3 20010315 (release)"