Question 6: (back)
Write a "TestBit" program. This program requires two integer inputs. The first value is a 32-bit integer to test; the second value is an unsigned integer in the range 0..31 describing which bit to test. The program should display true if the corresponding bit (in the test value) contains a one, the program should display false if that bit position contains a zero. The program should always display false if the second value holds a value outside the range 0..31.
program Question6;
#include( "stdlib.hhf" );
static
a: int32;
b: int8;
cnt: uns8;
okay: boolean := false;
found: boolean := false;
begin Question6;
stdout.put( "Please Enter an integer: " );
stdin.get( a );
mov (false, okay );
repeat
stdout.put( "Please enter a bit to test between 0..31: " );
stdin.get( b );
if( b >= 0 ) then
if( b <= 31 ) then
mov( b, bl );
mov( true, okay );
endif;
endif;
until( okay );
mov( a, eax );
mov( 0, cnt );
repeat
mov( false, okay );
shr( 1, eax );
if( @c ) then
mov( true, found );
else
mov( false, found );
endif;
if( cnt = bl ) then
mov(true, okay);
else
add( 1, cnt );
endif;
until( okay);
stdout.put( "TestBit: ", cnt, " = ", found, nl );
end Question6;