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 screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
19 var text-storage: (stream byte 0x200)
20 var text/esi: (addr stream byte) <- address text-storage
21 load-sector data-disk, 0/lba, 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-sector data-disk, 0/lba, 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 }