aboutsummaryrefslogtreecommitdiffstats
path: root/hello_world.subv
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-07-06 10:26:46 +0000
committers-ol <s+removethis@s-ol.nu>2021-07-06 11:08:54 +0000
commit631f09462050c8173dacb22a83e6ef3dacc3c8a1 (patch)
tree4cbd147e158991e229ce1fc2001525078a020b83 /hello_world.subv
parentgood helloworld example (diff)
downloadsubv-631f09462050c8173dacb22a83e6ef3dacc3c8a1.tar.gz
subv-631f09462050c8173dacb22a83e6ef3dacc3c8a1.zip
update README/ex example
Diffstat (limited to 'hello_world.subv')
-rw-r--r--hello_world.subv43
1 files changed, 43 insertions, 0 deletions
diff --git a/hello_world.subv b/hello_world.subv
new file mode 100644
index 0000000..60d9065
--- /dev/null
+++ b/hello_world.subv
@@ -0,0 +1,43 @@
+== code 0x80000000
+ # load mhartid CSR into t0, trap all but first Hart
+ 73/system 5/rd/t0 2/funct3/csrrs 0/rs/x0 f14/imm12/mhartid
+ 63/branch 1/subop/!= 5/rs/t0 0/rs/x0 0/off13
+
+main:
+ # x4 = &message
+ # . load high bits
+ 37/lui a/rd/a0 Message/imm20hi
+ # . add low bits
+ 13/opi 0/subop/add 4/rd/x4 a/rs/a0 Message/imm12lo
+ # call print
+ 6f/jal 1/rd/ra print/off21
+loop:
+ # infinite loop
+ 6f/jal 0/rd/x0 loop/off21
+
+print:
+ # load 0x10010000 (UART0) into t0
+ 37/lui 5/rd/t0 0x10010/imm20
+print:loop:
+ # load unsigned byte at x4
+ 03/load 4/subop/byte 6/rd/t1 a/rs/a0 0/imm12
+ # break loop if zero
+ 63/branch 0/subop/== 6/rs/t1 0/rs/x0 print:break/off13
+print:spin:
+ # spin if FIFO is full
+ 03/load 2/subop/word 7/rd/t2 5/rs/t0 0/imm12
+ 63/branch 4/subop/< 7/rs/t2 0/rs/x0 print:spin/off13
+ # print char
+ 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
+ # increment x4
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 1/imm12
+ # jump back up
+ 6f/jal 0/rd/x0 print:loop/off21
+print:break:
+ # return
+ 67/jalr 0/subop 0/rd/x0 1/rs/ra 0/off12
+
+== data 0x80500000
+Message:
+ # "Hello World!\n\0"
+ 48/8 65/8 6c/8 6c/8 6f/8 20/8 77/8 6f/8 72/8 6c/8 64/8 21/8 0a/8 00/8