https://github.com/akkartik/mu/blob/master/apps/advent2020/1a.mu
 1 fn main -> _/ebx: int {
 2   # data structure
 3   var numbers-storage: (array int 0x100)  # 256 ints
 4   var numbers/esi: (addr array int) <- address numbers-storage
 5   var numbers-index/ecx: int <- copy 0
 6   # phase 1: parse each line from stdin and add it to numbers
 7   {
 8     var line-storage: (stream byte 0x100)  # 256 bytes
 9     var line/edx: (addr stream byte) <- address line-storage
10     {
11 #?       print-string 0, "== iter\n"
12       # read line from stdin
13       clear-stream line
14       read-line-from-real-keyboard line
15       # if line is empty (not even a newline), quit
16       var done?/eax: boolean <- stream-empty? line
17       compare done?, 0  # false
18       break-if-!=
19 #?       print-stream-to-real-screen line
20       # convert line to int and append it to numbers
21       var n/eax: int <- parse-decimal-int-from-stream line
22 #?       print-int32-decimal 0, n
23 #?       print-string 0, "\n"
24       var dest/ebx: (addr int) <- index numbers, numbers-index
25       copy-to *dest, n
26       numbers-index <- increment
27 #?       print-string 0, "== "
28 #?       print-int32-decimal 0, numbers-index
29 #?       print-string 0, "\n"
30       loop
31     }
32   }
33   # phase 2: for each number in the array, check if 2020-it is in the rest of
34   # the array
35   var i/eax: int <- copy 0
36   {
37     compare i, numbers-index
38     break-if->=
39     var src/ebx: (addr int) <- index numbers, i
40 #?     print-int32-decimal 0, *src
41 #?     print-string 0, "\n"
42     var target/ecx: int <- copy 0x7e4  # 2020
43     target <- subtract *src
44     {
45       var found?/eax: boolean <- find-after numbers, i, target
46       compare found?, 0  # false
47       break-if-=
48       print-string 0, "found\n"
49       print-int32-decimal 0, *src
50       print-string 0, " "
51       print-int32-decimal 0, target
52       print-string 0, "\n"
53       target <- multiply *src
54       print-int32-decimal 0, target
55       print-string 0, "\n"
56       return 0  # success
57     }
58     i <- increment
59     loop
60   }
61   return 1  # not found
62 }
63 
64 fn find-after _numbers: (addr array int), start: int, _target: int -> _/eax: boolean {
65   var numbers/esi: (addr array int) <- copy _numbers
66   var target/edi: int <- copy _target
67   var len/ecx: int <- length numbers
68   var i/eax: int <- copy start
69   i <- increment
70   {
71     compare i, len
72     break-if->=
73     var src/edx: (addr int) <- index numbers, i
74     # if *src == target, return true
75     compare *src, target
76     {
77       break-if-!=
78       return 1  # true
79     }
80     i <- increment
81     loop
82   }
83   return 0  # false
84 }