Mercurial > hg > CbC > CbC_examples
annotate asmtest2.c @ 20:c181f93d4e30
minor fix
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 Jan 2016 09:53:21 +0900 |
parents | ead7c2743f0e |
children | 39ae2535ad2c |
rev | line source |
---|---|
17
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h> |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 __code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env) |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 { |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 if (n<0) { |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 printf("#0008:err %d!\n",n); |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 goto (*exit1)(0,exit1env); |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 } |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 if (n==0) |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 goto (*print)(n,result,orig,print,exit1,exit1env); |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 else { |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 result *= n; |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 n--; |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 goto factorial(n,result,orig,print,exit1,exit1env); |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 } |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 } |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 int main( int ac, char *av[]) |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 { |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 int n; |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 n = 10; |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 goto factorial(n,1,n,print,__return,__environment); |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 return 10; |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 } |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 __code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env) |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 { |
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 printf("#0032:%d! = %d\n",orig, result); |
20 | 30 asm volatile( |
31 "movq (%%rdi), %%r10;" | |
32 "movq $0, (%%r10);" | |
33 "movq 0x8(%%rdi), %%r10;" | |
34 "movq 0x8(%%r10), %%rbp;" | |
35 "movq 0x10(%%r10), %%rsp;" | |
36 "jmpq *0x38(%%r10);" | |
19
ead7c2743f0e
return value is correct
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
37 :"+D"(exit1env)::"r10" |
ead7c2743f0e
return value is correct
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
38 ); |
17
a4f44624a253
asm longjmp (can return correct address but return value is wrong)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 } |