https://github.com/akkartik/mu/blob/main/linux/apps/advent2017/1a.mu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 fn main -> _/ebx: int {
17 var input_stream: (stream byte 0x8000)
18 var input_stream_addr/esi: (addr stream byte) <- address input_stream
19
20 var sum/edi: int <- copy 0
21 read-line-from-real-keyboard input_stream_addr
22
23 var temp/eax: int <- read_digit input_stream_addr
24 var first_digit/ebx: int <- copy temp
25 var this_digit/edx: int <- copy temp
26
27 {
28 var done?/eax: boolean <- stream-empty? input_stream_addr
29 compare done?, 1
30 break-if-=
31
32 var next_digit/eax: int <- read_digit input_stream_addr
33
34 compare next_digit, 0
35 break-if-<
36
37 {
38 compare this_digit, next_digit
39 break-if-!=
40 sum <- add this_digit
41 }
42
43 this_digit <- copy next_digit
44
45 loop
46 }
47
48
49 {
50 compare this_digit, first_digit
51 break-if-!=
52 sum <- add this_digit
53 }
54
55 print-int32-decimal 0, sum
56
57 return 0/ok
58 }
59
60 fn read_digit input_stream_addr: (addr stream byte) -> _/eax: int {
61 var next_digit/eax: byte <- read-byte input_stream_addr
62 next_digit <- subtract 0x30
63 var next_digit/eax: int <- copy next_digit
64 return next_digit
65 }