view test/regargs.c @ 935:7672a37e7545 default tip

Raspbery PI ARM support begin
author kono
date Sat, 24 Dec 2016 03:02:57 +0000
parents c55337499f96
children
line wrap: on
line source

int printf(const char *format, ...);

extern  unsigned long strlen(const char *s);


void
arg1(int a1,int a2,int a3,int a4)
{
    printf("#0008:%d %d %d %d\n",a1,a2,a3,a4);
}

void
arg0(int a1,int a2,int a3,int a4)
{
    arg1(0,1,2,3);
    printf("#0015:%d %d %d %d\n",a1,a2,a3,a4);
}


static int gcd(int i0,int j0)
{
    register int k,i=i0,j=j0;
    if (i<j) { k=i; i=j; j=k;}
    for(;;) {
        if ((k=i%j)==0) return j;
        i = j; j = k;
    }
}

static int test_register()
{
    register int a=122,b=22,c=34,d=44,e=5,f;
    printf("#0032: %d %d %d %d %d\n",a,b,c,d,e);

    f = gcd(a,b);
    e = gcd(c,d);
    f = gcd(a,f);
    e = gcd(a,e);
    printf("#0038: %d %d %d %d %d\n",a,b,c,d,e);
    return 0;    
}

static char *float_one_lib[] = {
  "        .literal8",
"        .align 3",
"__float_one:",
"        .long   0",
"        .long   1072693248",
        0
};

static int float_one_lib_used = 1;

static void
emit_lib(char *p[])
{
  while(*p) {
    printf("#0057:%s\n",*p++);
  }
}

void
code_closing()
{
  if (float_one_lib_used) emit_lib(float_one_lib);
}

void
return_value()
{
    printf("#0070:%ld\n",strlen("test"));
    int ia =3, ib = 4;
    printf("#0072:%d\n", ia*ib >ib? ia*3 : ia/4);
    float fa =3, fb = 4;
    printf("#0074:%f\n", fa*fb >fb? fa*3 : fa/4);
    double ga =3, gb = 4;
    printf("#0076:%g\n", ga*gb >gb? ga*3 : ga/4);
    long long la =3, lb = 4;
    printf("#0078:%lld\n", la*lb >lb? la*3 : la/4);
}


int
main()
{
    arg0(0,1,2,3);
    test_register();
    code_closing();
    return_value();
    return 0;
}