MS-DOS下的16位x86机器代码-45字节
十六进制转储:
0E5F576A12595188ECE44088C3E44130D8240374F400C4AAE2EF595E80FC2475DFAC0432CD29B020CD29E2F5C3
Base64编码的二进制文件:
Dl9XahJZUYjs5ECIw+RBMNgkA3T0AMSq4u9ZXoD8JHXfrAQyzSmwIM0p4vXD
实际的源代码并带有一些注释:
bits 16
org 0x100
again:
push cs ; Save whatever CS we get.
pop di ; Use CS:DI as our course buffer..
push di ; Save for later use in the print loop
push 18 ; We need 18 holes for our golf course.
pop cx ; ch = 0, cl = 18.
push cx ; Save for later use.
mov ah, ch ; Zero out ah.
generate_course:
in al, 0x40 ; Port 0x40 is the 8253 PIT Counter 0.
mov bl, al ; Save the first "random" value in bl.
in al, 0x41 ; Port 0x41 is the 8253 PIT Counter 1.
xor al, bl ; Add some more pseudo randomness.
and al, 3 ; We only need the two lower bits.
jz generate_course ; If zero, re-generate a value, since we need only 3, 4, 5 holes.
add ah, al ; Sum in ah register.
stosb ; Store in the course buffer.
loop generate_course ; Loop for 18 holes.
pop cx ; cx = 18.
pop si ; si = course buffer.
cmp ah, 36 ; 72 holes?
jne again ; No, re-generate the whole course.
print: ; Yup, we have a nice course.
lodsb ; Load the next hole.
add al, '2' ; Add ASCII '2' to get '3', '4' or '5'
int 0x29 ; Undocumented MS-DOS print function.
mov al, ' ' ; Print a space too for better readability.
int 0x29 ; Print the character.
loop print ; Print the whole course.
ret ; Return to the beginning of the PSP where a INT 0x20 happen to be.
使用nasm 18h.asm -o 18h.com
32位Windows版本的MS-DOS(或Dosbox)或NTVDM进行编译并在其中运行。
样本输出:
4 5 4 5 4 5 3 4 3 4 3 4 4 5 4 3 5 3