CARDIAC › Tips and tricks › Room
Load tables with the program, not with INP
Say you want to look up the number of days in a month from a table of twelve.
You'd probably read the table in with INP when the program starts, using a little loop that rewrites its own INP to fill cells 40 to 51.
cell contents notes
10 030 INP 30 cell 10: the month
11 040 INP 40 cells 11-16: then read the table's 12 cards into cells 40-51
12 111 CLA 11
13 200 ADD 00
14 611 STO 11
15 731 SUB 31
16 311 TAC 11
17 130 CLA 30 cells 17-23: the days in month m are in cell 39 + m
18 232 ADD 32
19 620 STO 20
20 100 CLA 00 CLA 39 + m, written by the cell before
21 633 STO 33
22 533 OUT 33
23 900 HRS 00
30 000
31 052 INP 52
32 139 CLA 39
33 000
Step through the natural way in Cardigan
Instead, put the table on the program's own deck. The loader drops each entry into its cell on the way in, so your program doesn't need a fill loop at all. Loading isn't free, it costs three instructions a cell, but a fill loop pays that and more. One caveat: for a single value, a plain INP is still cheaper.
cell contents notes
10 030 INP 30 cells 10-17: the days in month m are in cell 39 + m
11 130 CLA 30
12 231 ADD 31
13 614 STO 14
14 100 CLA 00 CLA 39 + m, written by the cell before
15 632 STO 32
16 532 OUT 32
17 900 HRS 00
30 000
31 139 CLA 39
32 000
40 031 cells 40-51: the table, on the program's own deck
41 028
42 031
43 030
44 031
45 030
46 031
47 031
48 030
49 031
50 030
51 031
Step through the CARDIAC way in Cardigan
Both print 30 for September. Counting the loading, reading the table in takes 18 cells and runs 140 instructions, and loading it with the program takes 23 cells and runs 83.
How the loader places a table, and how Cardigan's DATA cells get you there: programming basics.
From the tips in
cardiac-code on GitHub. All the tips.