Mercurial > hg > CbC > CbC_examples
changeset 16:23ad5811c88f
asm longjmp (can return correct address but return value is wrong)
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jan 2016 06:00:37 +0900 |
parents | f889a158ce07 |
children | a4f44624a253 |
files | conv1/benchmark.sh fact-a2.c |
diffstat | 2 files changed, 39 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/conv1/benchmark.sh Sat Apr 18 01:52:44 2015 +0900 +++ b/conv1/benchmark.sh Sun Jan 24 06:00:37 2016 +0900 @@ -1,7 +1,7 @@ #!/usr/bin/env zsh time=/usr/bin/time -CONV1=./a.out +CONV1=./$1 num=10 count=0 @@ -9,10 +9,10 @@ max=0 min=99999 -echo "$CONV1 $1" +echo "$CONV1 $2" while [[ $count -lt $num ]]; do # /usr/bin/time -p ./conv1 1 2>&1 >& - |grep '^user'|tr -s " "|cut -f2 -d" " - usertime=$( $time -p $CONV1 $1 2>&1 >& - |grep '^user'|tr -s " " |cut -f2 -d" ") + usertime=$( $time -p $CONV1 $2 2>&1 >& - |grep '^user'|tr -s " " |cut -f2 -d" ") echo $usertime amount=$(($usertime+$amount))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fact-a2.c Sun Jan 24 06:00:37 2016 +0900 @@ -0,0 +1,36 @@ +#ifdef GCC +#define __environment _CbC_environment +#define __return _CbC_return +#endif + +#include "stdio.h" + +__code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env) +{ + if (n<0) { + printf("#0008:err %d!\n",n); + goto (*exit1)(0,exit1env); + } + if (n==0) + goto (*print)(n,result,orig,print,exit1,exit1env); + else { + result *= n; + n--; + goto factorial(n,result,orig,print,exit1,exit1env); + } +} + + +int main( int ac, char *av[]) +{ + int n; + n = 10; + goto factorial(n,1,n,print,__return,__environment); +} + +__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env) +{ + printf("#0032:%d! = %d\n",orig, result); + goto (*exit1)(0,exit1env); +} +