~charles/awk-riscv

ref: 42fd79a2b22dd6c42ae21c5095bdc4503ce9ec5f awk-riscv/tests/simulation/fibo.txt -rw-r--r-- 1.4 KiB
42fd79a2Charles Daniels get fibo test case working 1 year, 17 days ago
                                                                                
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
# keep assembling instructions until we see "mode normal"
mode assemble

# This program computes the value of the nth number in the Fibonacci sequence,
# where n is read from memory address 0x10000. The result is written to memory
# address 0x10004.

lui x5 0x10
lw x10 x5 0        # n <- mem[0x10000]
addi x11 x0 1      # i <- 1
addi x12 x0 0      # F[0] <- 0
addi x13 x0 1      # F[1] <- 1
addi x14 x0 0      # next <- 0

# x12 and x13 will be used to track the previous two elements of the fibonacci
# sequence as we advance through the loop

blt x13 x10 input_is_other      # if n > 1

input_is_zero:
jal x0 end

input_is_one:
jal x0 end

input_is_other:

fibo:
add x14 x12 x13         # next <- F[i] + F[i-1]
add x12 x0 x13          # F[i-1] <- F[i]
add x13 x0 x14          # F[i] <- next
addi x11 x11 1          # i++
blt x11 x10 fibo        # while(i < n)

end:
sw x5 x13 4   # mem[0x10004] <- F[n]

# return to normal mode so we can process other directives
mode normal

# resolve all branch and jump targets
resolve

# dump contents of memory
dump

# write input parameter, we will find the 20th Fibonacci number
poke 0x10000 20

# run the CPU for 2500 steps
step 2500

# dump the memory state again
dump

# view the results written back to this memory location
peek 0x10004

# this is used by the test suite to verify that this program gets the correct
# result
assert mem 0x10004 0x1a6d