Friday, 22 February 2019

Assembly: Commencing countdown, engines on

How long does it take a program written in assembly language to countdown from 1 billion to zero?


Find out for yourself, lazybones:

program countdown;
#include( "stdlib.hhf" )
static
    // Will countdown from 1 billion
    num: dword := $3B9ACA00;

begin countdown;
    mov( num, eax );
    stdout.put( "Starting from " );
    stdout.put( eax );
    stdout.put( " (1 billion)" );
    stdout.put( nl );

    countDownLoop:
        dec( eax );
        jg countDownLoop;
    stdout.put( "Reached zero. Splat." );
    stdout.put( nl );

end countdown;
(Post-script: It was approx. 300 times faster than Python.)