PPK debuts the tiny programming challenge
kernelistic writes "Looks like the great folks at properkernel.com are running a developer challenge. They're looking for smallest executables that match the posted criteria. The rules look fairly straightforward. Anyone up for some fun?"
Hang on a sec .. they say they'll accept Linux syscalls being used, but to call them you need to use the 'fastcall' approach, that is, put your arguments in the registers and run an interrupt (int 0x80 in Linux.)
But rule 3 states that you have to use a stack-based approach, no fastcall allowed! Wtf?
Just for comparison's sake, the quick'n'dirty approach:
main()
{
char *msg = "The deep gray mouse runs after the holy yellow cheese.\n";
write(1, msg, 56);
}
produces, stripped, a 3200 byte binary -- too big to qualify by 700 bytes.
-- Alastair
The catch? I did it in 5,038 bytes, including a nifty color icon.
Beat that.
TANSTAAFI: There Ain't No Such Thing As A Free iPod.
It's a nice challenge, but I think they should have been a bit more specific in the rules ('Preferably no fastcall binaries') and stated a more challenging task than putting out a string.
"A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
justin@joker:~/tmp[1]$ cat small.s
./small
:P
; Justin White
; http://properkernel.com/tiny/ entry
%define STDOUT 0
%define SYS_exit 1
%define SYS_write 4
section data
msg db "The deep gray mouse runs after the holy yellow cheese.", 0x0A
msg_size equ $-msg
section text
global _start
_start:
; write
push dword msg_size
push dword msg
push dword STDOUT
mov eax, SYS_write
push eax
int 0x80
; exit
push dword 0
mov eax, SYS_exit
push eax
int 0x80
; end _start
;EOF
justin@joker:~/tmp[0]$ nasm -f elf small.s
justin@joker:~/tmp[0]$ ld -x -s -o small -nostdlib --stats small.o
/usr/libexec/elf/ld: total time in link: 0.006606
/usr/libexec/elf/ld: data size 184328
justin@joker:~/tmp[0]$ ll small
-rwxrwxr-x 1 justin justin 516 Nov 25 03:22 small*
justin@joker:~/tmp[0]$
The deep gray mouse runs after the holy yellow cheese.
justin@joker:~/tmp[0]$
that's using FreeBSD kernel calls.
that's the smallest it'll be without doing ELF header tweaking like in that tiny binary tutorial.
actually, can save like 8 bytes by using just AL and not all of EAX to hold the syscall numbers.
now, if they said, do it without using the kernel, that would have been a challenge
--Justin