git.s-ol.nu subv / a7f7cdd
fix ask_name STDIO s-ol 19 days ago
1 changed file(s) with 18 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
66 # $ ./subv.sh examples/ask_.subv >examples/ask_.elf
77 # $ cat 2>dev/null | ./qemu.sh examples/ask_.elf
88 # What's your name?
9 # > Sol
9 # > Sol
1010 # Hello Sol, nice to meet you!
1111
1212 == code 0x80400000
1515 # 63/branch 1/subop/!= 5/rs/t0 0/rs/x0 0/off13
1616
1717 main:
18 6f/jal 1/rd/ra init/off21
19
2018 # print HELLO_WHATSURNAME
2119 37/lui a/rd/a0 HELLO_WHATSURNAME/imm20hi
2220 13/opi a/rd/a0 0/subop/add a/rs/a0 HELLO_WHATSURNAME/imm12lo
21 6f/jal 1/rd/ra print/off21
22
23 # read in Name
24 37/lui a/rd/a0 PROMPT/imm20hi
25 13/opi a/rd/a0 0/subop/add a/rs/a0 PROMPT/imm12lo
2326 6f/jal 1/rd/ra print/off21
2427
2528 37/lui a/rd/a0 Name/imm20hi
5255 # ECALL
5356 73/system 0/subop/priv 0/funct12/ecall
5457
55 init:
56 # initialize UART0
57 # load 0x10000000 (UART0) into t0
58 37/lui 5/rd/t0 10000/imm20
59
60 # disable interrupts
61 23/store 0/width/b 5/rs/t0 1/off12 0/rs/x0
62
63 # enable DLAB
64 13/opi 6/rd/t1 0/subop/add 0/rs/x0 80/imm12
65 23/store 0/width/b 5/rs/t0 3/off12 6/rs/t1
66
67 # max speed = 38400bps
68 13/opi 6/rd/t1 0/subop/add 0/rs/x0 3/imm12
69 23/store 0/width/b 5/rs/t0 0/off12 6/rs/t1
70 23/store 0/width/b 5/rs/t0 1/off12 0/rs/x0
71
72 # disable DLAB
73 13/opi 6/rd/t1 0/subop/add 0/rs/x0 3/imm12
74 23/store 0/width/b 5/rs/t0 3/off12 6/rs/t1
75
76 # enable fifo, clear, watermark=14b
77 13/opi 6/rd/t1 0/subop/add 0/rs/x0 c7/imm12
78 23/store 0/width/b 5/rs/t0 2/off12 6/rs/t1
79
80 # set dtr, srs, aux2
81 13/opi 6/rd/t1 0/subop/add 0/rs/x0 b/imm12
82 23/store 0/width/b 5/rs/t0 4/off12 6/rs/t1
83
84 13/opi 6/rd/t1 0/subop/add 0/rs/x0 1/imm12
85 23/store 0/width/b 5/rs/t0 1/off12 6/rs/t1
86
87 # return
88 67/jalr 0/subop 0/rd/x0 1/rs/ra 0/off12
89
90 old:
91 # set "data terminal ready" and "request to send" bits in MCR
92 13/opi 6/rd/t1 0/subop/add 0/rs/x0 3/imm12
93 23/store 0/width/b 5/rs/t0 4/off12 6/rs/t1
94 # return
95 67/jalr 0/subop 0/rd/x0 1/rs/ra 0/off12
96
9758 print:
9859 # print a C-string from a0
9960 # load 0x10000000 (UART0) into t0
12283 # read a C-string into a0
12384 # load 0x10000000 (UART0) into t0
12485 37/lui 5/rd/t0 10000/imm20
125 # load 0x0a (\n) into t1
126 13/opi 6/rd/t1 0/subop/add 0/rs/x0 0a/imm12
86 # load 0x0d (\r) into t1
87 13/opi 6/rd/t1 0/subop/add 0/rs/x0 0d/imm12
12788
12889 read:loop:
12990 # spin if FIFO is empty (data_ready = UART+5 & 1)
13495 03/load 7/rd/t2 4/width/bu 5/rs/t0 0/imm12
13596 # break loop if newline (t2 == t1)
13697 63/branch 0/subop/== 7/rs/t2 6/rs/t1 read:break/off13
137 # store char from t1 at [a0]
138 23/store 0/width/b a/rs/a0 7/rs/t2 0/off12
98 # echo and store char from t2
99 23/store 0/width/b 5/rs/t0 0/off12 7/rs/t2
100 23/store 0/width/b a/rs/a0 0/off12 7/rs/t2
139101 # increment a0
140102 13/opi a/rd/a0 0/subop/add a/rs/a0 1/imm12
141103 # jump back up
142104 6f/jal 0/rd/x0 read:loop/off21
143105 read:break:
106 # echo \n
107 13/opi 7/rd/t2 0/subop/add 0/rs/x0 0a/imm12
108 23/store 0/width/b 5/rs/t0 0/off12 7/rs/t2
144109 # return
145110 67/jalr 0/rd/x0 0/subop 1/rs/ra 0/off12
146111
155120 NICETOMEETU:
156121 # ", nice to meet you!\n\0"
157122 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
123 PROMPT:
124 # "> "
125 3e/8 20/8 00/8
158126 Name:
159 00/8
127 0/256