The PPK Tiny Programming Results 23
mikemacd writes "As mentioned before the folks over at properkernel.com ran a programming challenge. The results are in. Hopefuly they will post code too."
There is no opinion so absurd that some philosopher will not express it. -- Marcus Tullius Cicero, "Ad familiares"
Hmmm (Score:2)
Given that the winner used only 102 bytes, this means that his main code took up only 48 bytes. Wow.
Re:Hmmm (Score:3, Interesting)
Re:Hmmm (Score:2)
Re:Hmmm (Score:3, Interesting)
-s
Re:Hmmm (Score:5, Interesting)
So you have to write a minimal header, then print a string.
For some perspective: the normal ELF header is 52 bytes long, and the string including line feed is 55 bytes. The winner did it in 102, less than the sum of those. Wow.
The next thought: why in heck didn't they print source (as if he didn't build that binary by hand), the binaries, or any info at all about how they did this!! It's stupid to look at the results only, so many questions, so few answers...
Re:Hmmm (Score:2)
Re:Hmmm (Score:1)
Wow!
Smallest web browser yet? (Score:2)
They didn't SAY components couldn't live elsewhere, did they?
Re:Smallest web browser yet? (Score:1)
Re:Smallest web browser yet? (Score:2)
Pipe http://server/message | stdout
That's not an ELF binary. Can you make a binary that does that in 102 bytes?
Any particular reason why... (Score:2, Insightful)
And why is the shortest entry an incredibly huge 102 bytes when the above link does something similar in
It would've been more of a contest if the program was supposed to do something more than output a string like that.
Re:Any particular reason why... (Score:2)
I also think it would be a more interesting contest if the binary had to do something usefull. That would have meant more interesting optimization.
Re:Any particular reason why... (Score:1)
The contest actually required that a number of arguments to be set up, a syscall be called, AND control be returned to the operating system. Though this might seem trivial, it still adds overall bytes to the program. (Think of it this way, the string is 55ish bytes long then you have to add the ELF header and the code!)
Re:Any particular reason why... (Score:2)
Re:Any particular reason why... (Score:1)
My 155 byte entry (Score:2, Informative)
I use al,bl,cl,dl instead of eax,ebx,ecx,edx because they are only one byte wide instead of 4 bytes saving 3 whole bytes per use !!!
; Created by Michael MacDonald (mikemacd@sympatico.ca)
;
; Thanks to: http://www.muppetlabs.com/~breadbox/software/tiny
BITS 32
org 0x00001000
ehdr: ; Elf32_Ehdr
db 0x7F, "ELF", 1, 1, 1 ; e_ident
times 9 db 0
dw 2 ; e_type
dw 3 ; e_machine
dd 1 ; e_version
dd _start ; e_entry
dd phdr - $$ ; e_phoff
dd 0 ; e_shoff
dd 0 ; e_flags
dw ehdrsize ; e_ehsize
dw phdrsize ; e_phentsize
dw 1 ; e_phnum
dw 0 ; e_shentsize
dw 0 ; e_shnum
dw 0 ; e_shstrndx
ehdrsize equ $ - ehdr
phdr: ; Elf32_Phdr
dd 1 ; p_type
dd 0 ; p_offset
dd $$ ; p_vaddr
dd $$ ; p_paddr
dd filesize ; p_filesz
dd filesize ; p_memsz
dd 5 ; p_flags
dd 0x1000 ; p_align
phdrsize equ $ - phdr
section data
msg db "The deep gray mouse runs after the holy yellow cheese.", 0x0A
len equ $-msg
_start:
mov dl, len
mov cx, msg
mov bl, 1
mov al, 0x4
int 0x80
mov al,1
int 0x80
filesize equ $ - $$
My 99 byte entry (with cheat) (Score:1)
Compile (nasm -f bin -o tiny2 tiny2.asm), make executable (chmod o+x tiny2), and execute (./tiny2 "The deep gray mouse runs after the holy yellow cheese.\
")
*Note the carriage return in the argument, and again I use al,bl,cl,dl instead of eax,ebx,ecx,edx because they are only one byte wide instead of 4 bytes saving 3 whole bytes per use.
; Created by Michael MacDonald (mikemacd@sympatico.ca)
;
; Thanks to: http://www.muppetlabs.com/~breadbox/software/tiny
BITS 32
org 0x08048000
ehdr: ; Elf32_Ehdr
db 0x7F, "ELF", 1, 1, 1 ; e_ident
times 9 db 0
dw 2 ; e_type
dw 3 ; e_machine
dd 1 ; e_version
dd _start ; e_entry
dd phdr - $$ ; e_phoff
dd 0 ; e_shoff
dd 0 ; e_flags
dw ehdrsize ; e_ehsize
dw phdrsize ; e_phentsize
dw 1 ; e_phnum
dw 0 ; e_shentsize
dw 0 ; e_shnum
dw 0 ; e_shstrndx
ehdrsize equ $ - ehdr
phdr: ; Elf32_Phdr
dd 1 ; p_type
dd 0 ; p_offset
dd $$ ; p_vaddr
dd $$ ; p_paddr
dd filesize ; p_filesz
dd filesize ; p_memsz
dd 5 ; p_flags
dd 0x1000 ; p_align
phdrsize equ $ - phdr
_start:
pop eax
pop ecx
pop ecx
mov dl,55
mov bl,1
mov al,4
int 128
mov al,1
int 128
filesize equ $ - $$
Elf binary? Bah! (Score:4, Funny)
Code and bins for the entries... (Score:2, Informative)
Not a winner? (Score:4, Informative)
'The deep ' 0x0 0x1 0x0 ' gray mouse runs after the holy yellow cheese.' 0xA
Where the 0x0 0x1 0x0 are required fields in the ELF header that splits the message into two halves. The output might appear to be correct when displayed on a terminal but if you redirect it to a file you will see the extra bytes.
Modifying the code to not output the extra bytes would add 9 bytes to the program and it would larger than the next smallest binary, assuming that the 104 byte entry didn't use the same trick.
Yay! I got on the high scores! (Score:2, Informative)
The source (yes, nasm input == source) to my entry is available here [menloschool.org].
Cody P. article (Score:1)