Saturday 23 February 2019

Assembly: Sub-routine to display a range of characters

This program repeatedly calls a sub-routine to display a range of characters.

The first and last character to be displayed in each range can be set using the al and cl 8-bit registers before calling the sub-routine.



Code:

program display_chars;

#include( "stdlib.hhf" )


// Phil Gardner

procedure displayCharRange; @noframe; @nodisplay;
begin displayCharRange;

    keepDisplaying:

        stdout.put( ( type char al ), " " );
        inc( al );
        cmp( al, cl );
    jle keepDisplaying;

    ret();

end displayCharRange;


// - - - - -

begin display_chars;


    // Display all upper-case letters

    mov( $41, al );
    mov( $5A, cl );
    call displayCharRange;

    stdout.put( nl );

    // Display all lower-case letters

    mov( $61, al );
    mov( $7A, cl );
    call displayCharRange;

    stdout.put( nl );

    // Display all numeric digits

    mov( $30, al );
    mov( $39, cl );
    call displayCharRange;

    stdout.put( nl );

    // Display punctuation symbols

    mov( $21, al );
    mov( $2F, cl );
    call displayCharRange;

    
    mov( $3A, al );
    mov( $40, cl );
    call displayCharRange;

    mov( $5B, al );
    mov( $60, cl );
    call displayCharRange;

    mov( $7B, al );
    mov( $7E, cl );
    call displayCharRange;

    stdout.put( nl );

end display_chars;