Asamblea x86, 512 bytes
Compilado con NASM y probado con QEMU. Para arrancar, debe poner una firma de arranque de 2 bytes al final del sector de arranque (510 bytes en el archivo), por lo que perdí 317 bytes llenando el código compilado con ceros. Este es mi primer golf, así que tengo que disculparme por cualquier error gigantesco.
[org 7c00h] ;So NASM can change the labels into memory locations correctly.
cld ;Tells lodsb to look forward in memory
mov bh, 65 ;Moves the ASCII value of A into the BH register
mov si, NATO ;Moves the first byte of NATO into the si register
call print ;Call the 'print' subroutine
jmp $ ;Loops forever
print:
mov ah, 0eh ;Moves the hex value 0E into the AH register. Tells interrupt 10h that we want subfucntion 0E
lodsb ;Load a byte of SI into AL and increments a register (DL i think) that tells it the offset to look at
cmp al, 3 ;Compares the AL register that now has a byte from our string to ASCII value 3 (Enf Of Text)
je R ;If AL == 3 then jump to R
cmp al, 0 ;Comapre AL to ASCII 0 (NULL)
je newWord ;If AL == 0 hump to newWord
int 10h ;Execute interrupt 10h Subfunction 0Eh (stored in AH register) which prints character value in AL
jmp print ;Jump to print
newWord:
mov al, 10 ;Move ASCII 10 (New Line) into AL
int 10h ;Print character
mov al, 13 ;Move ASCII 13 (Carriage Return) into AL
int 10h ;Print character
mov al, bh ;Move BH (which has our starting letter) into AL
int 10h ;Print Character
mov al, 58 ;Move ASCII 58 (:) into AL
int 10h ;Print Character
mov al, 32 ;Move ASCII 32 (Space) into AL
int 10h ;Print Character
mov al, bh ;Move BH into AL
int 10h ;Print Character
inc bh ;Increments BH by one (BH++)
jmp print ;Jump to print
R:
ret ;Returns from a subroutine
;Below defines bytes (db) of our string to print. I used 0 as word seperators and 3 to end the string.
NATO: db 0,"lfa",0,"ravo",0,"harlie",0,"elta",0,"cho",0,"oxtrot",0,"olf",0,"otel",0,"ndia",0,"uliet",0,"ilo",0,"ima",0,"ike",0,"ovember",0,"scar",0,"apa",0,"uebec",0,"omeo",0,"ierra",0,"ango",0,"niform",0,"ictor",0,"hiskey",0,"ray",0,"ankee",0,"ulu",3
times 0200h - 2 - ($ - $$) db 0 ;Zerofill the file with upto 510 bytes (This is where all my bytes are)
dw 0AA55H ;Write the bootsignature
Salida
Esto es lo que genera el código anterior. Como puede ver A: falta Alfa y eso se debe a que el indicador tiene 25 líneas de alto ...
Para demostrar que imprimí A: Alfa I reemplazó 0,"ulu"
con el 32,"Z: Zulu"
fin de que Zulu es una en la misma línea que el Yankee.
Agradecería que alguien me dijera si podría restar los 317 bytes de zerofill de mi código para que sean 195 bytes. Además, si esto es válido porque la salida no cabe en la pantalla.