~charles/awk-riscv

ref: fa3c47fde6c5a46743f34bc972ece337a8974615 awk-riscv/fibo.txt -rw-r--r-- 1.4 KiB
fa3c47fdCharles Daniels assemble lw and sw 1 year, 1 month 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
# set n
poke 0x10000 20

# poke in the program, execution starts at 0, this code was assembled using
# RARS
poke 0x00000000  0x000102b7  # lui x5,0x00000010
poke 0x00000004  0x00028293  # addi x5,x5,0x00000000
poke 0x00000008  0x0002a503  # lw x10,0x00000000(x5)
poke 0x0000000c  0x00100593  # addi x11,x0,0x000000017
poke 0x00000010  0x00000613  # addi x12,x0,0x000000008
poke 0x00000014  0x00100693  # addi x13,x0,0x000000019
poke 0x00000018  0x00000713  # addi x14,x0,0x0000000010
poke 0x0000001c  0x00a6ce63  # blt x13,x10,0x0000000e15
poke 0x00000020  0xf0201073  # csrrw x0,0x00000f02,x018
poke 0x00000024  0xf0301073  # csrrw x0,0x00000f03,x019
poke 0x00000028  0x02c0006f  # jal x0,0x00000016
poke 0x0000002c  0xf0269073  # csrrw x0,0x00000f02,x123
poke 0x00000030  0xf0369073  # csrrw x0,0x00000f03,x124
poke 0x00000034  0x0200006f  # jal x0,0x00000010
poke 0x00000038  0x00d60733  # add x14,x12,x13
poke 0x0000003c  0x00d00633  # add x12,x0,x13
poke 0x00000040  0x00e006b3  # add x13,x0,x14
poke 0x00000044  0x00158593  # addi x11,x11,0x000000033
poke 0x00000048  0xf0269073  # csrrw x0,0x00000f02,x134
poke 0x0000004c  0xf0359073  # csrrw x0,0x00000f03,x135
poke 0x00000050  0xfea5c4e3  # blt x11,x10,0xfffffff436
poke 0x00000054  0x00d2a223  # sw x13,0x00000004(x5)

# advance simulation by 10000 CPU cycles
step 10000

# read the result, note that the 20th fibonacci number is 6765, which is 0x1a6d
peek 0x10004