x86 .COM Executable, 7
in hex:
b8 21 0e cd 10 eb fc
The others need kilobytes or more of system libraries and runtime. Back to basics:
$ echo -ne '\xb8!\xe\xcd\x10\xeb\xfc' > A.COM
$ dosbox A.COM
You can change the 2nd byte (0x21
, or !
) to change the output.
Uses a BIOS interrupt for output; doesn't need DOS, but I didn't have QEMU set up.
Explanation
The machine code corresponds with the following assembly:
mov ax, 0x0e21
again: int 0x10
jmp again
The output is all in the int
call -- per this reference, int 0x10 with 0x0e in AH will print the byte in AL to the screen.
Knowing that register AX is a 16-bit word comprised of AH in the high byte and AL in the low byte, we can save an extra load (and thereby a byte in the machine code) by loading them together.