4 ms·
It's worth noting that at one point there was an effort to standardise ABIs on Unix-like OSs, https://en.wikipedia.org/wiki/Intel_Binary_Compatibility_Standard
by userbinator 4y ago
It's worth noting that at one point there was an effort to standardise ABIs on Unix-like OSs, https://en.wikipedia.org/wiki/Intel_Binary_Compatibility_Standard https://en.wikipedia.org/wiki/Intel_Binary_Compatibility_Sta... although it seems to have mostly been forgotten by the Internet.
(I dug into that a little bit, inspired by a previous article here: https://news.ycombinator.com/item?id=31456401 https://news.ycombinator.com/item?id=31456401 )
Four operating systems is under 400 bytes is pretty good!
I have a 26-byte Hello World that works in DOS 1.x, 2.x, 3.x, 4.x, 5.x, 6.x, Windows 1.x, 2.x, 3.x, 95, 98, 98se, Me, 2k, XP, Vista, 7, 8, 10. If I used CALL 5 I might get down into CP/M-land but possibly miss some of the newer OSs ;-)
- yjftsjthsd-h 4y agoI'll grant DOS, maybe win16, Windows 9x, and NT, but it's a bit much to count multiple versions of the same OS and I'm on the fence about compatibility layers - can I include WINE and say that the same binary also works on Darwin, Linux, and Illumos? (If that binary works on DOS 1.x, I seriously doubt that that it's any more "native" on modern Windows that on, say, Illumos; they're both just using an ABI compatibility layer)
- jchw 4y agoIt comes with some other caveats: no AMD64 version of Windows has ever shipped NTVDM, so for newer OSes it will only work on the x86 32 variant. (Though, I do believe some variants of Windows on other architectures had NTVDM with an x86 emulator, and so this 26 byte binary is also cross architecture!)
- jchw 4y agoI 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
- rep_lodsb 4y agoFor supporting both CP/M and DOS, you can skip over an 8080 jump instruction using a single extra byte: 80 C3 xx xx The first instruction will be harmless on both processors, and even have the same mnemonic: it decodes as either "ADD BX,xxxx" or "ADD B"!
- rep_lodsb 4y agosmall correction: the first byte is 81, "ADD C" on the 8080