program powersOfTwo;
// Phil Gardner
#include( "stdlib.hhf" )
begin powersOfTwo;
// Start at 1, then double repeatedly
mov( 1, eax );
mov( 1, bl );
display:
stdout.put( "Col no. " );
stdout.puti8( bl );
stdout.put( ": " );
mov( bl, cl );
dec( cl );
stdout.put( " 2 to the power of " );
stdout.puti8( cl );
stdout.put( " is " );
stdout.puti32( eax );
stdout.put( nl );
shl( 1, eax );
inc( bl );
cmp( bl, 16 );
jle display;
end powersOfTwo;
program binary_shifts;
#include( "stdlib.hhf" )
// Phil Gardner
begin binary_shifts;
// Base 10 number to be converted to 7-bit binary
mov( 45, ax );
// Start at leftmost column
mov( 64, cl );
stdout.put( nl, "Convert " );
stdout.puti16( ax );
stdout.put( " to 7-bit binary:" );
stdout.put( nl );
processColumn:
// Determine whether this column fits into number
// Divides ax by cl
div( cl );
stdout.put( nl, "Place value in cl " );
stdout.puti8( cl );
stdout.put( stdio.tab, "quotient in al " );
stdout.puti8( al );
stdout.put( stdio.tab, "modulo in ah " );
stdout.puti8( ah );
// Expand the modulo into ax
mov( ah, al );
cbw();
// Update place value to use for next column
shr( 1, cl );
// Decide whether all columns now completed
cmp( cl, 0 );
jg processColumn;
finished:
stdout.put( nl, nl, "Finished.", nl );
end binary_shifts;