(hey Kragen, how did the bytebeat performances go?)
Apropos the bootstrapping thread[0], here's another hex loader:
0000000: 31c9 bf00 03ba 8a01 b40a cd21 a18b 013c 1..........!...<
0000010: 047c 17b8 0001 01c8 bb00 0202 1e8c 0189 .|..............
0000020: 07be 8c01 a5a5 9041 ebdb 31c0 a320 0289 .......A..1.. ..
0000030: cd31 c9be 0003 bf00 02bb 0100 31c9 31d2 .1..........1.1.
0000040: b800 42cd 21b8 0040 cd21 ac31 d231 c0ac ..B.!..@.!.1.1..
0000050: 3c20 740f bb01 0101 cb29 da01 f889 c38b < t......)......
0000060: 0701 c231 c0ac 0c20 d410 d503 2c09 c0e0 ...1... ....,...
0000070: 0401 c2ac 0c20 d410 d503 2c09 01c2 9090 ..... ....,.....
0000080: b402 cd21 4139 e975 c1c3 5000 ...!A9.u..P.
The main advantage of keying in the extra 100 bytes is to gain branch
relocation with (mono-)symbolic labels, facilitating alternations and
repetitions, and hence paving the way for real (or at least multiple
character) symbol tables and automated handling of other relocations
[1]. Its format is fairly restrictive[2], with the first 4
characters of each line defining an output byte:
0: defines a label
1: calculates a pc-relative reference to a label
2: high nybble value
3: low nybble value
As an example, here's a load file for a variant of fr-16:
b8
13
00 # mov ax,13
cd
10 # int 10
c4
2f # les bp,[bx]
l aa # loop: stosb
11
f8 # adc ax,di
15
32
11 # adc ax,1132
eb
l00 # jmp loop
(or see the footnotes for the "source"[3])
In principle, there's one branch too many[4] in this code; it should
be possible to run the second pass entirely in straight-line code.
On the other hand, 15 additional bytes and slight modifications to
the input format suffice to provide absolute relocations without any
additional logic...
-Dave
[0] http://lists.canonical.org/pipermail/kragen-discuss/2011-April/
[1] in fact, if one adds enough evaluation to an assembler it becomes
indistinguishable from a linker ... conversely, a sufficiently
advanced linker is indistinguishable from an assembler. cf
Jones DW, "Assembly Language as Object Code", SP&E 13, Aug 1983
Fraser & Hanson, "A Machine Independent Linker", SP&E 12, Apr 1982
http://drhanson.s3.amazonaws.com/storage/documents/link.pdf
[2] have I mentioned that my first PL/1 program failed to compile
because I had mistakenly entered code in the first 6 columns?
[3] encoded here with newlines replaced by commas:
31, c9, bf, 00, 03,A ba, 8a, 01, b4, 0a, cd, 21, a1,
8b, 01, 3c, 04, 7c, B00, b8, 00, 01, 01, c8, bb, 00, 02,
02, 1e, 8c, 01, 89, 07, be, 8c, 01, a5, a5, 90, 41, eb,
A00,B 31, c0, a3, 20, 02, 89, cd, 31, c9, be, 00, 03,
bf, 00, 02, bb, 01, 00, 31, c9, 31, d2, b8, 00, 42, cd,
21, b8, 00, 40, cd, 21,G ac, 31, d2, 31, c0, ac, 3c, 20,
74, D00, bb, 01, 01, 01, cb, 29, da, 01, f8, 89, c3, 8b,
07, 01, c2,D 31, c0, ac, 0c, 20, d4, 10, d5, 03, 2c, 09,
c0, e0, 04, 01, c2, ac, 0c, 20, d4, 10, d5, 03, 2c, 09,
01, c2, 90, 90, b4, 02, cd, 21, 41, 39, e9, 75, G00, c3,
50, 00,
[4] the first pass loop-and-a-half could also lose a branch if one
specified that loader files must end with, say, the string ' []' as a
tombstone.
--
To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-discuss