Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

CONTEST - Paragraph Print

Name: Anonymous 2010-01-19 1:00

Write the smallest possible program that can print the following paragraph (sans quotes):

"Educators, generals, dieticians, psychologists, and parents program. Armies, students, and some societies are programmed. An assault on large problems employs a succession of programs, most of which spring into existence en route. These programs are rife with issues that appear to be particular to the problem at hand. To appreciate programming as an intellectual activity in its own right you must turn to computer programming; you must read and write computer programs -- many of them. It doesn't matter much what the programs are about or what applications they serve. What does matter is how well they perform and how smoothly they fit with other programs in the creation of still greater programs. The programmer must seek both perfection of part and adequacy of collection. In this book the use of ``program'' is focused on the creation, execution, and study of programs written in a dialect of Lisp for execution on a digital computer. Using Lisp we restrict or limit not what we may program, but only the notation for our program descriptions."

The quote must be printed in verbatim. Any language may be used. Programs are rated on the size of their compiled executable form, not the lines of code. Record holder has to draw an ASCII medal for whoever surpasses him.

The following is my entry. It's uncompressed, unoptimized C code, and it compiles to 18475 bytes using the standard GCC settings on Win32. I hope that it will be surpassed shortly.

#include <stdio.h>

int main (void)
{
    printf("Educators, generals, dieticians, psychologists, and parents program. Armies, students, and some societies are programmed. An assault on large problems employs a succession of programs, most of which spring into existence en route. These programs are rife with issues that appear to be particular to the problem at hand. To appreciate programming as an intellectual activity in its own right you must turn to computer programming; you must read and write computer programs -- many of them. It doesn't matter much what the programs are about or what applications they serve. What does matter is how well they perform and how smoothly they fit with other programs in the creation of still greater programs. The programmer must seek both perfection of part and adequacy of collection. In this book the use of ``program'' is focused on the creation, execution, and study of programs written in a dialect of Lisp for execution on a digital computer. Using Lisp we restrict or limit not what we may program, but only the notation for our program descriptions.");
    return 0;
}


Your move, /prog/.

Name: 34 2010-01-20 0:00

Looks like I managed to beat my own record at this:

.586
.model flat,stdcall
option casemap:none

   include windows.inc
   include user32.inc
;  include kernel32.inc
  
   includelib user32.lib
;  includelib kernel32.lib


.code

    textCompressedBlob dd 75640045h, 6F746163h, 2C077372h, 6E656720h, 6C181F2Fh, 0F6696415h, 0EB63E674h, 199D6EF1h, 87791E70h, 276C6F68h, 74ADFF67h, 64289B1Fh, 6D72AB26h
    dd 0DF101A56h, 6D622C63h, 0CF41CB2Eh, 3BB1645Dh, 0A3647544h, 1F3F2734h, 0B726D6Fh, 3C4D8D63h, 326B46FFh, 6B643066h, 73266E67h, 6C75A31Fh, 766FDB74h, 673ECA16h, 0BB629E20h, 85A6DB6h
    dd 79E69BF7h, 0A082416Bh, 6E7C7AC7h, 666A4969h, 0D3C5CD41h, 1280DCF6h, 0AAA36877h, 32DD4C9Eh, 0BA676ECFh, 78CB0C08h, 0DABAA78h, 14B66C87h, 756C6068h, 6854DA18h, 0E87F8868h, 6662CC8Ch
    dd 0AD770ACEh, 5EB47A74h, 14A159CAh, 0B8A4B961h, 3CDFFB70h, 6A628F33h, 0A0081461h, 0D01184A2h, 0FDB7A140h, 0E4ACFA55h, 33A36FB3h, 742E9E54h, 8C21E0A7h, 0F4CFEE3Bh, 6C658692h, 1A634864h
    dd 20B1EF7Dh, 9B76690Eh, 542D79E4h, 556F4106h, 67F0A177h, 799ACA68h, 0E7D220A7h, 72285016h, 63736D6Eh, 0BAAB70FEh, 3B5338EDh, 0E23127A5h, 65236461h, 0F0807736h, 0B6B32E8Fh, 0DB528E2Dh
    dd 66FAD440h, 0A4A6B892h, 647D6A49h, 276EE6A0h, 5133BEFFh, 3992AA2Ch, 0CBAB7773h, 0DE1C4457h, 375B6212h, 77482478h, 696CE214h, 84A5266Ah, 0AC2C1B73h, 76497EBEh, 3C573456h, 53635624h
    dd 2C144869h, 506C7734h, 708829F3h, 6D8E6619h, 1A03AB4Dh, 0F9EFDF73h, 4A046C32h, 2BBC661Eh, 69293482h, 32EC04BDh, 0E6AF6393h, 1EF97412h, 3EA976F4h, 0A5E724D1h, 568FD924h, 201D9378h
    dd 906BF49Eh, 7FA9D1BFh, 4463567Dh, 8A43CF52h, 4865E678h, 63249071h, 34DD6E1Eh, 502325B0h, 0C4457824h, 6B2978BFh, 4A9CB782h, 69601C24h, 69279C63h, 6DD220E3h, 0DE8E3363h, 2C4DA7BCh
    dd 7594657Ah, 1CD0B24h, 9B790F34h, 69AE4AB6h, 4FE19B28h, 28665DF6h, 4C21817Ah, 0AF70AC99h, 68424A72h, 674623BAh, 0E04CD462h, 55A30BB4h, 5C080A09h, 0D7774430h, 92C83DC4h, 0AB3563A6h
    dd 276DA309h, 0B2AF6E4Fh, 0A13DB566h, 7B597995h, 44629102h, 7A6E49D1h, 5A562690h, 0EB457441h, 0E2B2512Dh, 0D20F63A2h, 2EEB33h
    db    0
   
.data?
    szText db 041Bh dup(?)
    szCaption db 2 dup(?)
.code
 
start:
    push offset szText
    push offset textCompressedBlob   
    call aP_depack_asm
    add esp,8
    invoke MessageBox,0,offset szText,offset szCaption,MB_OK
   
    ;removing this call, even though it's not really proper, but should work on NT and 9x, as long as you're not using some weird PE packers
    ;invoke ExitProcess,eax
    ret
   
;; Compression function   
aP_depack_asm:
    ; aP_depack_asm(const void *source, void *destination)

    _ret$  equ 7*4
    _src$  equ 8*4 + 4
    _dst$  equ 8*4 + 8

    pushad

    mov    esi, [esp + _src$] ; C calling convention
    mov    edi, [esp + _dst$]

    cld
    mov    dl, 80h
    xor    ebx,ebx

literal:
    movsb
    mov    bl, 2
nexttag:
    call   getbit
    jnc    literal

    xor    ecx, ecx
    call   getbit
    jnc    codepair
    xor    eax, eax
    call   getbit
    jnc    shortmatch
    mov    bl, 2
    inc    ecx
    mov    al, 10h
getmorebits:
    call   getbit
    adc    al, al
    jnc    getmorebits
    jnz    domatch
    stosb
    jmp    nexttag
codepair:
    call   getgamma_no_ecx
    sub    ecx, ebx
    jnz    normalcodepair
    call   getgamma
    jmp    domatch_lastpos

shortmatch:
    lodsb
    shr    eax, 1
    jz     donedepacking
    adc    ecx, ecx
    jmp    domatch_with_2inc

normalcodepair:
    xchg   eax, ecx
    dec    eax
    shl    eax, 8
    lodsb
    call   getgamma

    cmp    eax, 32000
    jae    domatch_with_2inc
    cmp    ah, 5
    jae    domatch_with_inc
    cmp    eax, 7fh
    ja     domatch_new_lastpos

domatch_with_2inc:
    inc    ecx

domatch_with_inc:
    inc    ecx

domatch_new_lastpos:
    xchg   eax, ebp
domatch_lastpos:
    mov    eax, ebp

    mov    bl, 1

domatch:
    push   esi
    mov    esi, edi
    sub    esi, eax
    rep    movsb
    pop    esi
    jmp    nexttag

getbit:
    add    dl, dl
    jnz    stillbitsleft
    mov    dl, [esi]
    inc    esi
    adc    dl, dl
stillbitsleft:
    ret

getgamma:
    xor    ecx, ecx
getgamma_no_ecx:
    inc    ecx
getgammaloop:
    call   getbit
    adc    ecx, ecx
    call   getbit
    jc     getgammaloop
    ret

donedepacking:
    sub    edi, [esp + _dst$]
    mov    [esp + _ret$], edi ; return unpacked length in eax

    popad

    ret



end start


;    This product uses the aPLib compression library,
;    Copyright © 1998-2009 by Jørgen Ibsen, All Rights Reserved.
;    For more information, please visit: http://www.ibsensoftware.com/

Compile this with the same settings as in >>34, but this won't give you a tiny file as it generates a .data section and masm won't let you use code in the header and similar things.
To minimize filesize, I used aplib's own compression to decompress the string, and the decompressor is fairly tiny itself, after that I abused the PE format quite a bit by moving the PE header into the DOS header(partially), and moving part of the data into the header. This is by 104 bytes smaller than the MEW compressed executable. Since most of the optimizations were done by hand in a hex editor, with the help of a PE editor, I can't give you a program which does it(I could write one, but I don't really plan on doing this more than once, so I just did it by hand), however I can post the executable here,

toy_msg3.exe.base64:

TVqQAABzdXAgL3Byb2cvP1BFAABMAQEAAAAAAAAAAAAAAAAA4AAPAQsBBQygAwAAIAQAAAAAAACh
AwAAEAAAAKAFAAAAAEAAEAAAABAAAAAEAAAABAAAAAQAAAAAAAAAkgUAAAACAAAAAAAAAgAAAAAA
EAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAAeAQAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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bAQ6E8AAAASwHP3dT+q
69ToTQAAACvLdRDoQgAAAOsorNHodE0TyesckUjB4Ais6CwAAAA9AH0AAHMKgPwFcwaD+H93AkFB
lYvFswFWi/cr8POkXuuOAtJ1BYoWRhLSwzPJQeju////E8no5////3Lywyt8JCiJfCQcYcP/JTAB
QADMzKAEAAAAAAAAAAAAALYEAAAwAQAAAAAAAAAAAAAAAAAAAAAAAAAAAACoBAAAAAAAALEBTWVz
c2FnZUJveEEAdXNlcjMyLmRsbA==

1216 bytes total. My old record was 2816 uncompressed, and 1320 compressed MEW PE executable.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List