-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday1.tal
89 lines (57 loc) · 2 KB
/
day1.tal
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
82
83
84
85
86
87
88
89
%EMIT { #18 DEO }
%DBGBYTE { DUP ;print-byte JSR2 #0a EMIT }
%DBGSHORT { DUP2 ;print-short JSR2 #0a EMIT }
( devices )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
( init )
|0100 @program
( load contents from file )
#3000 .File/length DEO2
;filename .File/name DEO2
;contents .File/read DEO2
( .File/success DEI2 ;print-short JSR2 #0a EMIT )
;contents ( contents )
&next-digit
DUP2 INC2 SWP2 ( contents+1 contents )
LDA ( contents+1 next-byte )
DUP #0b LTH ,&next-number JCN
( DBGBYTE )
#30 SUB #00 SWP ( contents+1 next-digit-as-short )
( DBGSHORT )
;current-number LDA2 #000a MUL2 ( contents+1 digit-as-short num*10 )
( DBGSHORT )
ADD2 ( contents+1 num*10+digit )
( DBGSHORT )
;current-number STA2 ( contents+1 )
,&next-digit JMP
&next-number
#00 EQU ,&done JCN
( print current and current sum )
;current-number LDA2 ;print-short-decimal JSR2
#20 EMIT
;current-number LDA2 ;previous-number LDA2 ;preprevious-number LDA2 ADD2 ADD2 ;print-short-decimal JSR2
;current-number LDA2 ;prepreprevious-number LDA2 ( current prepreprevious )
GTH2 ( [1 if current > prepreprevious] )
#00 EQU ( [1 if current <= prepreprevious] ) ,&no-increment JCN
;increment-count LDA2 INC2 ;increment-count STA2
LIT '^ EMIT
&no-increment
#0a EMIT
;preprevious-number LDA2 ;prepreprevious-number STA2
;previous-number LDA2 ;preprevious-number STA2
;current-number LDA2 ;previous-number STA2
#0000 ;current-number STA2
;&next-digit JMP2
&done
;increment-count LDA2 ;print-short-decimal JSR2 #0a EMIT
BRK
~library/console.lib.tal
@filename "day1.txt 00
@current-number 00 00
@previous-number ff ff
@preprevious-number ff ff
@prepreprevious-number ff ff
@increment-count 00 00
@contents