Advent of Code 2018
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

6 years ago
#ip 4
; while (123 & 456 != 72);
00: seti 123 0 2
01: bani 2 456 2
02: eqri 2 72 2
03: addr 2 4 4
04: seti 0 0 4
05: seti 0 8 2 ; r2 = 0
; xref 30
06: bori 2 65536 5 ; r5 = r2 | 0x10000
07: seti 2238642 0 2 ; r2 = 2238642
; xref 27
08: bani 5 255 3 ; r3 = r5 & 0xff
09: addr 2 3 2 ; r2 = r2 + r3
10: bani 2 16777215 2 ; r2 = r2 & 0xffffff
11: muli 2 65899 2 ; r2 = r2 * 65899
12: bani 2 16777215 2 ; r2 = r2 & 0xffffff
; trash = r3
; keep = r2, r5
13: gtir 256 5 3 ; if (0x100 > r5)
14: addr 3 4 4 ; then
15: addi 4 1 4 ; (false) jr +1 (17)
16: seti 27 3 4 ; (true ) jp 27 (28)
; xref 16 (256 <= r5)
; r5 >>= 8
17: seti 0 8 3 ; r3 = 0
18: addi 3 1 1 ; r1 = r3 + 1
19: muli 1 256 1 ; r1 = r1 * 0x100
20: gtrr 1 5 1 ; if (r1 > r5)
21: addr 1 4 4 ; then
22: addi 4 1 4 ; ..
23: seti 25 4 4 ; ..
24: addi 3 1 3 ; (false) r3 = r3 + 1
25: seti 17 2 4 ; (false) jp 17 (18)
26: setr 3 9 5 ; (true ) r5 = r3
27: seti 7 9 4 ; (true ) jp 07 (08)
; xref 16 (256 > r5)
28: eqrr 2 0 3 ; if (r2 == r0)
29: addr 3 4 4 ; then
30: seti 5 0 4 ; (false) jp 05 (06)
; (true ) exit
; ===== HIGH-LEVEL PSEUDOCODE =====
r2 = 0
do {
r5 = r2 | 0x10000
r2 = 2238642
while (1) {
// r2 = (r2 + r5) * 65899
r2 = (((r2 + (r5 & 0xff)) & 0xffffff) * 65899) & 0xffffff
if (0x100 > r5) break
r5 >>= 8
}
} while (r2 != r0)