minimal useful bootsectors
return

I was curious how small I could make a “useful” boot sector image, excluding the padding for the BIOS header. The keypress counts are not optimized, and could likely be reduced significantly, but their relative magnitude between solutions would remain similar.

Solution 1, 20 bytes, 68 keypresses to hello world

mov di, end
cld
l:
xor ax, ax
push ax
pop es
int 0x16
xchg ax, bx
xor ax, ax
int 0x16
mul bl
stosb
jc l

Figuring out the appopriate sequence of keys to press for this example is trivial.

Solution 2, 13 bytes, 178 keypresses to hello world

loader_size equ LOADER_SIZE
loader_bot equ jmp_insn + 1
loader_top equ loader_bot + loader_size - 1

mov di, loader_top
std
l:
xor ax, ax
push ax
pop es
int 0x16
stosb
jmp_insn:
jmp l

This requires limiting oneself to using instructions where the 7th bit of every byte is unset, so mild creativity and self modifying code is required to do much of anything useful. Note that an unconditional jump is used, but the loop is conditional because the loader itself will be overwritten by the user, thus terminating the loop and beginning execution of the inputted code in one fell swoop.

Solution 3, 11 bytes, 11843 keypresses to hello world

  db 0xBF
l:
db 0x07, 0xAA
std
xor ax, ax
push ax
int 0x16
jmp l

The vast majority of the keypresses in this example are a result of using a convenient address to begin writing the program to. Other than that, essentially identical to solution 2.