x86 Assembly, 512 byte
Dikompilasi dengan NASM dan diuji dengan QEMU. Untuk mem-boot Anda harus meletakkan tanda tangan boot 2 byte di ujung bootsector (510 byte ke dalam file) jadi saya kehilangan 317 byte mengisi kode yang dikompilasi dengan nol. Ini golf pertama saya, jadi saya harus minta maaf atas kesalahan raksasa.
[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
Keluaran
Inilah yang dihasilkan oleh kode di atas. Seperti yang Anda lihat A: Alfa hilang dan itu karena prompt adalah 25 baris ...
Untuk membuktikan saya mencetak A: Alfa saya diganti 0,"ulu"
dengan32,"Z: Zulu"
sehingga Zulu adalah satu di baris yang sama seperti Yankee.
Saya akan sangat menghargai jika seseorang mengatakan kepada saya jika saya dapat mengurangi 317 byte zerofill dari kode saya sehingga akan menjadi 195 byte. Juga jika ini bahkan valid karena output tidak muat di layar.