https://github.com/akkartik/mu/blob/main/ex9.mu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 fn main {
19 var text-storage: (stream byte 0x200)
20 var text/esi: (addr stream byte) <- address text-storage
21 load-first-sector-from-primary-bus-secondary-drive text
22
23 var word-count/eax: int <- word-count text
24
25 var result-storage: (stream byte 0x10)
26 var result/edi: (addr stream byte) <- address result-storage
27 write-int32-decimal result, word-count
28 store-first-sector-to-primary-bus-secondary-drive result
29 }
30
31 fn word-count in: (addr stream byte) -> _/eax: int {
32 var result/edi: int <- copy 0
33 {
34 var done?/eax: boolean <- stream-empty? in
35 compare done?, 0/false
36 break-if-!=
37 var g/eax: grapheme <- read-grapheme in
38 {
39 compare g, 0x20/space
40 break-if-!=
41 result <- increment
42 }
43 {
44 compare g, 0xa/newline
45 break-if-!=
46 result <- increment
47 }
48 loop
49 }
50 return result
51 }