Kernel word recovery crack, Mobile themes website for samsung wave 525, Dekha ek khwab sony tv title song, Song zombies on your lawn, Bloody mary nerve endings mp3, Digittrade tv jukebox, Padosan songs mp3, Gold cup series 70 manual, Nieuwste versie van mozilla firefox en, Cant install spotify on mac, Web brute force password cracker, Belkin g peek driver windows 7

Gwaaaaaaah, this is brainfucked !

July 3rd, 2009 by Martijn Leave a reply »

It’s hot. Very hot. So hot that the heat messed up the working of my brain and reduced my thinking power to that of a below average sized stranded dead blue whale, or maybe a rabbit,  and caused me to—instead of finishing the parser library that I was hoping to finish days ago—letting my drifting thoughts guide my mouse arm into the darker places of the web, or at least a fairly darkish yellowish one, namely Blog Jaune.

What I found there could be an eternal source of horror to some, yet an source of extreme hilarity to others. To me, it was a source of shameful amusement: GWAAAAAAAH, a brainfuck-like language. Shame because I never took the time to play with brainfuck which set back from the role of  überhacker to that of newbie brainfuck virgin. Amusement because the code sample looks like this:

DAAAAAAAAAAhhhhhh ?
Rooooaaahahhahah!!
GAAAAAAAGAAAAAAAAAAGAAAGAWWWWOM!
GAAH!!
GAH
AAAAAAAH!
Haaaaaooa
BrrooaAAAH
GAAH
WWAAAAAAAAAAAAAAAH!!!!!!!
GeeaaahH!
AAAH
OOOOOOH
BlOOOOOOOOpppH
GAH!
GobidoaaahH !

This of course displays “Hello World!”. Amused as I was, I still felt my amusement level  dwell a little on the low side of the amusement scale, and suddenly it came to me: GWAAAAAAAH needed an interpreter written in perl. And some time later I had one, nice and short as perl programs can be.

Of course it needed some testing. To achieve this I looked for some brainfuck programs, translated them to GWAAAAAAAH, and tried to run them. Some bugs later, I had a nice working perl interpreter.

#!/usr/bin/perl
die "syntax: perl gwaaaaaaah.pl <file.gwa>"
    unless defined $ARGV[0] && -f $ARGV[0];
$/=undef;
$|=1;
open F, '<', $ARGV[0];
 
@CODE = split //, <F>;      # read-only code segment
$PC = 0;                    # program counter points to the byte after the last
                            # executed instruction in @CODE.
 
@M = ();                    # heap
$X = 0;                     # data register points to a byte in the heap.
 
@S = ();                    # looping stack
 
%inst = (
    G => sub { $X++ },
    W => sub { die '*___--- GAAAAAAA! ---___*' if --$X < 0 },
    A => sub { ++$M[$X]; $M[$X] %= 0xff },
    O => sub { --$M[$X]; $M[$X] %= 0xff },
    H => sub { print chr($M[$X]) },
    Z => sub { $M[$X]=getc; exit 0 unless defined $M[$X] },
    R => sub {
        if ( $M[$X] ) { push @S, $PC }
        else {
            $sb = 1;
            while ( $PC < @CODE ) {
                $mb = $CODE[ $PC++ ];
                if ( $mb eq 'R' ) {++$sb }
                elsif ( $mb eq 'M' ) { last unless --$sb }
            }
        }
    },
    M => sub { $M[$X] ? $PC = $S[ $#S ] : pop @S },
);
 
while ( $PC < @CODE ) {
    $op = $CODE[$PC++];
    next unless exists $inst{$op};
    $inst{$op}();
}

The 99 bottles of beer program was running very slowly though. Admittedly, it could count bottles of beer faster than any human could drink, but it was not *instantaneous*, like how a good computer would do it. It struck me: I needed a compiler ! Interpreters are slow, GWAAAAAAAH needed to be compiled directly to assembler.

Some more hacking, and the interpreter was transformed into a compiler that generates nasm code. Some Makefile magic allowed to transform a .bf file into .gwa, then into .asm, into .o and finally into an executable.

I still had a last reason to be unsatisfied: the generated code was fairly verbose, matching the verbosity of the source: GWAAAAAAAH source files tend to contain many repeated characters, and it was easy to replace the generated increment/decrement instructions with add/sub instructions.

Voilà, small linux executables from GWAAAAAAAH sources. Now I can go back to hacking on my universal programmer-friendly not-so-optimized parser design.

Attached Files:

Advertisement

Leave a Reply

Authorized tags:
[b]bold[/b] [u]underline[/u] [i]italic[/i] [url=http://link.url]link[/url] more