-
Notifications
You must be signed in to change notification settings - Fork 0
/
year20-small.hrm
81 lines (64 loc) · 2.72 KB
/
year20-small.hrm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
-- HUMAN RESOURCE MACHINE PROGRAM --
-- 20: Multiplication Workshop
-- INSTRUCTIONS: "For each two things in the INBOX, multiply them, and
-- OUTBOX the result. Don't worry about negative numbers for now."
-- AVAILABLE COMMANDS: INBOX, OUTBOX, COPYFROM, COPYTO, ADD, SUB,
-- BUMPUP, BUMPDN, JUMP, JUMPZ, JUMPN, COMMENT
-- SIZE: 15 commands (challenge 15)
-- AVERAGE RUNTIME: 135 steps (challenge 109)
-- Tile 0: First value
-- Tile 1: Partial sum
-- Tile 2: Second value
-- Tile 9: Permanent zero
JUMP c
a:
COPYFROM 1
b:
OUTBOX
-- Save the value of the first item of a pair, and initialize the
-- partial sum with it.
c:
INBOX
COPYTO 0
COPYTO 1
-- If the second item of a pair has a value of zero, put it in the
-- outbox and move on to the next pair; otherwise, save it. (To minimize
-- program size, the case where the first item is zero is implicitly
-- handled by the repeated addition below, albeit inefficiently.)
INBOX
JUMPZ b
COPYTO 2
-- Repeatedly add the first value to the partial sum, using the second
-- value as a counter. (If the first value is zero, the partial sum
-- correctly ends up being zero.) After the correct number of additions,
-- put the partial sum in the outbox and move on to the next pair.
d:
BUMPDN 2
JUMPZ a
COPYFROM 1
ADD 0
COPYTO 1
JUMP d
DEFINE LABEL 0
eJyTYmBgYE34k8WUmBpVlzQ72DxV0GdDureHeCGHm1t5RGBD5fNouyq1zurqndM21UWs1Wx6vCW5RW37
xa7MnQcn3NtoMSVkVdE0jkUfpjXNBRrFwDxhi3l73w6rNw0H89zKtXoiCwKWG6WbH2YYJKC7dOc0EJ3d
u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