~charles/awk-riscv

0b93f104af9f11a78838fbc210d790a977ac4823 — Charles Daniels 10 months ago 844fac2
remove unused fibo files
2 files changed, 0 insertions(+), 72 deletions(-)

D fibo.asm
D fibo.txt
D fibo.asm => fibo.asm +0 -39
@@ 1,39 0,0 @@
# 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.

li x5 0x10000
lw x10 0(x5)  # n <- mem[0x10000]
li x11 1      # i <- 1
li x12 0      # F[0] <- 0
li x13 1      # F[1] <- 1
li x14 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

bgt x10 x13 input_is_other      # if n > 1

input_is_zero:
csrw x0 io2
csrw x0 io3
j end

input_is_one:
csrw x13 io2
csrw x13 io3
j end

input_is_other:

fibo:
add x14 x12 x13         # next <- F[i] + F[i-1]
mv x12 x13              # F[i-1] <- F[i]
mv x13 x14              # F[i] <- next
addi x11 x11 1          # i++
csrw x13 io2            # HEX <- F[i]
csrw x11 io3            # LEDs <- i
blt x11 x10 fibo        # while(i < n)

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

D fibo.txt => fibo.txt +0 -33
@@ 1,33 0,0 @@
# 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