3 ms·
I love the tricks that can be done with the old COM format. It's so versatile and simple, its almost like scripting. You can even make it ASCII clean while reta
by jchw 4y ago
I love the tricks that can be done with the old COM format. It's so versatile and simple, its almost like scripting. You can even make it ASCII clean while retaining some semblence of turing completeness!
I had a weird and pointless project somewhat recently where I wanted to bootstrap a programming environment using only the stock tools on NT 4. I didn't actually finish, but what I did write was pretty contrived. I wrote some code for JScript, which had to run in IE since there was no scripthost, and it would parse some horrible language using a very inefficient IE3 JScript compatible implementation of parser combinators and generate x86 code... And output it in base64 into a textarea. Which I would then need to somehow get back into proper binary data...
So my approach was to write a small DOS compatible COM binary with a really simple base64 decode routine. I'd do this with the DEBUG command, and save it to disk. Then, I'd use redirection in command prompt to feed it base64 and redirect the output to a file.
I was pretty ecstatic to see this awful hack job working somewhat end-to-end.
(I don't have the code, I think it got wiped out when the drive in the laptop I was doing this whole game on died. But it was quite straightforward to implement base64 in very little code; I believe what I wound up doing was accumulating 3 bytes of output from 4 bytes of input with a few conditionals to shift base64 symbols into the corresponding bits and then just some shifting and ORing. No LUTs necessary.)
- jart 4y agoDon't you need negative displacement to be turing complete? And wouldn't negative displacement always entail non-ascii characters?
- rep_lodsb 4y agoYou'll either need self modifying code or a chain of short jumps that wraps around the 64K code segment. The latter is used by http://tom7.org/abc http://tom7.org/abc
- EvanAnderson 4y agoI was reading the comments this morning and thinking "I know somebody did this fairly recently..." but couldn't remember who. Of course it was Tom7. Of. Course. Tom7 is a treasure.
- rep_lodsb 4y agoNot a base64 decoder (written those too), but here's an ASCII-only .COM file that works on both x86 and 8080: x)y'!B:)),DM!G@))p,T]l%)),@@@Hello, world!$XP5]A%=!P[PZ^V!wV!wX5.<(GV(gX534,!(GWr! it could have been a few bytes shorter, but on 486 you need a jump to flush the prefetch queue