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