https://github.com/akkartik/mu/blob/master/apps/advent2020/1a.mu
1 fn main -> _/ebx: int {
2
3 var numbers-storage: (array int 0x100)
4 var numbers/esi: (addr array int) <- address numbers-storage
5 var numbers-index/ecx: int <- copy 0
6
7 {
8 var line-storage: (stream byte 0x100)
9 var line/edx: (addr stream byte) <- address line-storage
10 {
11
12
13 clear-stream line
14 read-line-from-real-keyboard line
15
16 var done?/eax: boolean <- stream-empty? line
17 compare done?, 0
18 break-if-!=
19
20
21 var n/eax: int <- parse-decimal-int-from-stream line
22
23
24 var dest/ebx: (addr int) <- index numbers, numbers-index
25 copy-to *dest, n
26 numbers-index <- increment
27
28
29
30 loop
31 }
32 }
33
34
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
41
42 var target/ecx: int <- copy 0x7e4
43 target <- subtract *src
44 {
45 var found?/eax: boolean <- find-after numbers, i, target
46 compare found?, 0
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
57 }
58 i <- increment
59 loop
60 }
61 return 1
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
75 compare *src, target
76 {
77 break-if-!=
78 return 1
79 }
80 i <- increment
81 loop
82 }
83 return 0
84 }