Friday, 22 February 2019

Assembly: Push the stack over

How much data can you push on to the stack before your program falls over?



Let's have a look then...

program stack_zapper;

#include( "stdlib.hhf" )


// Phil Gardner


begin stack_zapper;


    stdout.put( nl );
    stdout.put( "Repeatedly push 4 byte value on to the stack." );
    stdout.put( nl );


    mov( $0000029A, eax );


    stdout.put( "eax = " );
    stdout.put( eax );

    stdout.put( nl, nl );

    mov( $00000000, ebx );


infiniteLoop:


    stdout.put( "Stack pointer = " );
    stdout.put( esp );

    stdout.put( nl );

    mov( $00004000, ecx );


pushBigChunk:


    push( eax );


    dec( ecx );


    jge pushBigChunk;


    stdout.put( "Pushed another 16 KB on to stack" );
    stdout.put( stdio.tab );


    inc( ebx );


    stdout.put( ebx );
    stdout.put( " x 16 KB" );
    stdout.put( stdio.tab );


    jmp infiniteLoop;


end stack_zapper;