diff options
| author | s-ol <s+removethis@s-ol.nu> | 2021-07-06 12:38:21 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2021-07-06 12:39:34 +0000 |
| commit | c299060bc82e4e198891f4abeb293619cda75090 (patch) | |
| tree | bd609bc2fb7108e18070db9e79c6f3c2a94dde55 /examples | |
| parent | fix hello_world comments (diff) | |
| download | subv-c299060bc82e4e198891f4abeb293619cda75090.tar.gz subv-c299060bc82e4e198891f4abeb293619cda75090.zip | |
reorganize, add ask_name example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/.gitignore | 2 | ||||
| -rw-r--r-- | examples/ask_name.subv | 104 | ||||
| -rw-r--r-- | examples/ex.elf | bin | 0 -> 8224 bytes | |||
| -rw-r--r-- | examples/ex.format | 16 | ||||
| -rw-r--r-- | examples/ex.pack | 16 | ||||
| -rw-r--r-- | examples/ex.subv | 16 | ||||
| -rw-r--r-- | examples/ex.survey | 16 | ||||
| -rw-r--r-- | examples/ex.valid | 16 | ||||
| -rw-r--r-- | examples/hello_world.subv | 42 |
9 files changed, 228 insertions, 0 deletions
diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..6a15fd6 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,2 @@ +*.elf +!ex.* diff --git a/examples/ask_name.subv b/examples/ask_name.subv new file mode 100644 index 0000000..b9e54bc --- /dev/null +++ b/examples/ask_name.subv @@ -0,0 +1,104 @@ +# ask for the user's name, +# then print it back with a hello message. +# +# until I figure out how to enable STDIN properly, +# requires running qemu like so: +# +# $ ./subv.sh examples/ask_.subv >examples/ask_.elf +# $ cat 2>dev/null | ./qemu.sh examples/ask_.elf +# What's your name? +# > Sol +# Hello Sol, nice to meet you! + +== code 0x80000000 + # trap all but first Hart (a0 = mhartid) + 63/branch 1/subop/!= a/rs/a0 0/rs/x0 0/off13 + +main: + # print HELLO_WHATSURNAME + 37/lui a/rd/a0 HELLO_WHATSURNAME/imm20hi + 13/opi 0/subop/add a/rd/a0 a/rs/a0 HELLO_WHATSURNAME/imm12lo + 6f/jal 1/rd/ra print/off21 + + 37/lui a/rd/a0 Name/imm20hi + 13/opi 0/subop/add a/rd/a0 a/rs/a0 Name/imm12lo + 6f/jal 1/rd/ra read/off21 + + # print HELLO_ + 37/lui a/rd/a0 HELLO_/imm20hi + 13/opi 0/subop/add a/rd/a0 a/rs/a0 HELLO_/imm12lo + 6f/jal 1/rd/ra print/off21 + + # print Name + 37/lui a/rd/a0 Name/imm20hi + 13/opi 0/subop/add a/rd/a0 a/rs/a0 Name/imm12lo + 6f/jal 1/rd/ra print/off21 + + # print NICETOMEETU + 37/lui a/rd/a0 NICETOMEETU/imm20hi + 13/opi 0/subop/add a/rd/a0 a/rs/a0 NICETOMEETU/imm12lo + 6f/jal 1/rd/ra print/off21 + + # infinite loop + 6f/jal 0/rd/x0 0/off21 + +print: +# print a C-string from a0 + # 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 (t2 sign bit is set) + 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 a0 + 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 + +read: +# read a C-string into a0 + # load 0x10010004 (UART0+4) into t0 + 37/lui 5/rd/t0 0x10010/imm20 + 13/opi 0/subop/add 5/rd/t0 5/rs/t0 4/imm12 + # load 0x0a (\n) into t1 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12 +read:loop: + # load word at a0 into t0 + 03/load 2/subop/word 7/rd/t2 5/rs/t0 0/imm12 + # spin if FIFO is empty (t2 sign bit is set) + 63/branch 4/subop/< 7/rs/t2 0/rs/x0 read:loop/off13 + # break loop if newline (t2 == t1) + 63/branch 0/subop/== 7/rs/t2 6/rs/t1 read:break/off13 + # store char at a0 + 23/store 2/width/word a/rs/a0 7/rs/t2 0/off12 + # increment a0 + 13/opi 0/subop/add a/rd/a0 a/rs/a0 1/imm12 + # jump back up + 6f/jal 0/rd/x0 read:loop/off21 +read:break: + # return + 67/jalr 0/subop 0/rd/x0 1/rs/ra 0/off12 + + +== data 0x80500000 +HELLO_WHATSURNAME: + # "What's your name?\n\0" + 57/8 68/8 61/8 74/8 27/8 73/8 20/8 79/8 6f/8 75/8 72/8 20/8 6e/8 61/8 6d/8 65/8 3f/8 0a/8 00/8 +HELLO_: + # "Hello \0" + 48/8 65/8 6c/8 6c/8 6f/8 20/8 00/8 +NICETOMEETU: + # ", nice to meet you!\n\0" + 2c/8 20/8 6e/8 69/8 63/8 65/8 20/8 74/8 6f/8 20/8 6d/8 65/8 65/8 74/8 20/8 79/8 6f/8 75/8 21/8 0a/8 00/8 +Name: + 00/8 diff --git a/examples/ex.elf b/examples/ex.elf Binary files differnew file mode 100644 index 0000000..a509aaf --- /dev/null +++ b/examples/ex.elf diff --git a/examples/ex.format b/examples/ex.format new file mode 100644 index 0000000..6727dd1 --- /dev/null +++ b/examples/ex.format @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +# main: +# load 0x10010000 (UART0) into t0 +37/7 05/5 10010/20 +# store 0x48 (H) in UART0+0 +13/7 06/5 0/3 00/5 048/12 +23/7 00/5 2/3 05/5 06/5 00/7 +# store 0x69 (i) in UART0+0 +13/7 06/5 0/3 00/5 069/12 +23/7 00/5 2/3 05/5 06/5 00/7 +# store 0x0a (\n) in UART0+0 +13/7 06/5 0/3 00/5 00a/12 +23/7 00/5 2/3 05/5 06/5 00/7 +# jump back up to the top +6f/7 00/5 ff/8 1/1 3f2/10 1/1 diff --git a/examples/ex.pack b/examples/ex.pack new file mode 100644 index 0000000..e0cb8b9 --- /dev/null +++ b/examples/ex.pack @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +# main: +# load 0x10010000 (UART0) into t0 +b7 02 01 10 +# store 0x48 (H) in UART0+0 +13 03 80 04 +23 a0 62 00 +# store 0x69 (i) in UART0+0 +13 03 90 06 +23 a0 62 00 +# store 0x0a (\n) in UART0+0 +13 03 a0 00 +23 a0 62 00 +# jump back up to the top +6f f0 5f fe diff --git a/examples/ex.subv b/examples/ex.subv new file mode 100644 index 0000000..408dabb --- /dev/null +++ b/examples/ex.subv @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +main: + # load 0x10010000 (UART0) into t0 + 37/lui 5/rd/t0 0x10010/imm20 + # store 0x48 (H) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 48/imm12 + 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12 + # store 0x69 (i) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 69/imm12 + 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12 + # store 0x0a (\n) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12 + 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12 + # jump back up to the top + 6f/jal 0/rd/x0 main/off21 diff --git a/examples/ex.survey b/examples/ex.survey new file mode 100644 index 0000000..e30860c --- /dev/null +++ b/examples/ex.survey @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +# main: +# load 0x10010000 (UART0) into t0 +37/u 5/rd 10010/imm20 +# store 0x48 (H) in UART0+0 +13/i 6/rd 0/funct3 0/rs 48/imm12 +23/s 5/rs1 0/imm12 2/funct3 6/rs2 +# store 0x69 (i) in UART0+0 +13/i 6/rd 0/funct3 0/rs 69/imm12 +23/s 5/rs1 0/imm12 2/funct3 6/rs2 +# store 0x0a (\n) in UART0+0 +13/i 6/rd 0/funct3 0/rs a/imm12 +23/s 5/rs1 0/imm12 2/funct3 6/rs2 +# jump back up to the top +6f/j 0/rd -1c/imm21 diff --git a/examples/ex.valid b/examples/ex.valid new file mode 100644 index 0000000..1652954 --- /dev/null +++ b/examples/ex.valid @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +main: +# load 0x10010000 (UART0) into t0 +37/u 5/rd 10010/imm20 +# store 0x48 (H) in UART0+0 +13/i 6/rd 0/funct3 0/rs 48/imm12 +23/s 5/rs1 0/imm12 2/funct3 6/rs2 +# store 0x69 (i) in UART0+0 +13/i 6/rd 0/funct3 0/rs 69/imm12 +23/s 5/rs1 0/imm12 2/funct3 6/rs2 +# store 0x0a (\n) in UART0+0 +13/i 6/rd 0/funct3 0/rs a/imm12 +23/s 5/rs1 0/imm12 2/funct3 6/rs2 +# jump back up to the top +6f/j 0/rd main/off21 diff --git a/examples/hello_world.subv b/examples/hello_world.subv new file mode 100644 index 0000000..579a0e6 --- /dev/null +++ b/examples/hello_world.subv @@ -0,0 +1,42 @@ +== code 0x80000000 + # trap all but first Hart (a0 = mhartid) + 63/branch 1/subop/!= a/rs/a0 0/rs/x0 0/off13 + +main: + # a0 = &message + # . load high bits + 37/lui a/rd/a0 Message/imm20hi + # . add low bits + 13/opi 0/subop/add a/rd/a0 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 a0 + 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 a0 + 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 |
