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