Question 8: (back)
Write a program that reads an eight-bit unsigned integer and a 16-bit unsigned integer from the user that computes and displays the sum and the absolute value of the difference of these two numbers.
program Question8;
#include( "stdlib.hhf" );
static
a: int32;
b: int32;
tmp1: int32;
tmp2: int32;
done: boolean := false;
begin Question8;
stdout.put( "Please enter an integer between 0..256: " );
stdin.getu8();
movzx( al, ax );
cwde();
mov( eax, a );
stdout.put( "Please enter an integer beteen 0..65535: " );
stdin.getu16();
movzx( ax, eax );
mov( eax, b );
// Calculate the sum
mov( a, eax );
mov( eax, tmp1 );
mov( b, eax );
add( eax, tmp1 );
stdout.put( "a + b = ", tmp1, nl);
// Calculate the difference
mov( b, eax );
mov( eax, tmp2 );
mov( a, eax );
sub( eax, tmp2 );
stdout.put( "b - a = ", tmp2, nl );
end Question8;