Question 2: (back)
Write a program that reads a single precision floating point value from the user, takes the absolute value of that number, and then displays the result. Hint: this program does not use any arithmetic instructions or comparisons. Take a look at the binary representation for floating point numbers in order to solve this problem.
program Question2;
#include( "stdlib.hhf" );
static
r: real32;
r2: real32;
cnt: int8;
cnt2: int8;
begin Question2;
mov( 0, eax );
stdout.put( "Please enter a real number: " );
stdin.get( r );
mov( (type dword r), eax );
stdout.newln();
stdout.put( "Binary: ");
mov( 0, cnt );
mov( 0, cnt2 );
while( cnt < 32 ) do
if( cnt2 = 4 ) then
stdout.put( "_" );
mov( 0, cnt2 );
endif;
shl( 1, eax );
if( @c ) then
stdout.put( "1" );
else
stdout.put( "0" );
endif;
inc( cnt );
inc( cnt2 );
endwhile;
end Question2;