Commit | Line | Data |
---|---|---|
4a71579b PC |
1 | .data 32 |
2 | format: | |
3 | .c "nfibs(%d) = %d\n" | |
4 | ||
5 | .code | |
6 | jmpi main | |
7 | ||
8 | name nfibs | |
9 | nfibs: | |
10 | prolog | |
11 | arg $in | |
12 | getarg %r0 $in // R0 = n | |
13 | beqi ref %r0 0 | |
14 | movr %r1 %r0 | |
15 | movi %r0 1 | |
16 | blei_u ref %r1 2 | |
17 | subi %r2 %r1 2 | |
18 | movr %r1 %r0 | |
19 | loop: | |
20 | subi %r2 %r2 1 // decr. counter | |
21 | movr %v0 %r0 // V0 = R0 | |
22 | addr %r0 %r0 %r1 // R0 = R0 + R1 | |
23 | movr %r1 %v0 // R1 = V0 | |
24 | bnei loop %r2 0 // if (R2) goto loop | |
25 | ref: | |
26 | retr %r0 // RET = R0 | |
27 | epilog | |
28 | ||
29 | name main | |
30 | main: | |
31 | prolog | |
32 | arg $argc | |
33 | arg $argv | |
34 | ||
79bfeef6 | 35 | getarg %r0 $argc |
4a71579b PC |
36 | blei default %r0 1 |
37 | getarg %r0 $argv | |
38 | addi %r0 %r0 $(__WORDSIZE >> 3) | |
39 | ldr %r0 %r0 | |
40 | prepare | |
41 | pushargr %r0 | |
42 | finishi @atoi | |
43 | retval %r0 | |
44 | jmpi call | |
45 | ||
46 | default: | |
47 | movi %r0 32 | |
48 | ||
49 | call: | |
50 | movr %v0 %r0 | |
51 | prepare | |
52 | pushargr %r0 | |
53 | finishi nfibs | |
54 | retval %r0 | |
55 | prepare | |
56 | pushargi format | |
57 | ellipsis | |
58 | pushargr %v0 | |
59 | pushargr %r0 | |
60 | finishi @printf | |
61 | ret | |
62 | epilog |