annotate test_arm.c @ 1918:6fdac0108e47

Fix bug in in (c) instruction in Z80 dynarec
author Michael Pavone <pavone@retrodev.com>
date Fri, 03 Apr 2020 23:47:57 -0700
parents 474270dbff15
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
553
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdio.h>
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "gen_arm.h"
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 typedef int32_t (*fib_fun)(int32_t);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 int main(int arc, char **argv)
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 {
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 code_info code;
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 init_code_info(&code);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 uint32_t *fib = code.cur;
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 subi(&code, r0, r0, 2, SET_COND);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 movi_cc(&code, r0, 1, NO_COND, CC_LT);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 bx_cc(&code, lr, CC_LT);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 pushm(&code, LR | R4);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 mov(&code, r4, r0, NO_COND);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 bl(&code, fib);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 mov(&code, r1, r0, NO_COND);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 addi(&code, r0, r4, 1, NO_COND);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 mov(&code, r4, r1, NO_COND);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 bl(&code, fib);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 add(&code, r0, r4, r0, NO_COND);
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22 popm(&code, LR | R4);
554
474270dbff15 Fix ARM code generation and test program
Michael Pavone <pavone@retrodev.com>
parents: 553
diff changeset
23 bx(&code, lr);
553
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 fib_fun fibc = (fib_fun)fib;
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 printf("fib(10): %d\n", fibc(10));
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 return 0;
1af6c1052993 Added untested code for generating ARM machine code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }