Hello,
I think these two functions will come in very handy to solving the "write
longword bits" problem.
****ftLeft( Left, Right, ****ft )
****ftRight( Right, Left, ****ft )
****fting with extra inputs is what is required to solve it nicely.
// Begin of Code ***
program Project1;
{$APPTYPE CONSOLE}
{
Skybuck presents ****ftLeft( Left, Right, ****ft ) and ****ftRight( Right,
Left, ****ft )
version 0.01 created on 5 may 2008 by Skybuck Flying.
Be carefull though, the ****ft parameter must be 0 to 31.
}
uses
SysUtils;
// make overloaded versions for easy coding
// display in big endian.
procedure WriteBitPattern( const ParaByte : byte ); overload;
type
TbitRange = 0..7;
TbitSet = set of TbitRange;
var
vBit : TbitRange;
begin
for vBit:= 0 to 7 do
begin
if vBit in TbitSet(ParaByte) then
begin
write('1');
end else
begin
write('0');
end;
end;
end;
procedure WriteBitPattern( const ParaWord : word ); overload;
type
TbitRange = 0..15;
TbitSet = set of TbitRange;
var
vBit : TbitRange;
begin
for vBit:= 0 to 15 do
begin
if vBit in TbitSet(ParaWord) then
begin
write('1');
end else
begin
write('0');
end;
end;
end;
procedure WriteBitPattern( const ParaLongWord : longword ); overload;
type
TbitRange = 0..31;
TbitSet = set of TbitRange;
var
vBit : TbitRange;
begin
for vBit:= 0 to 31 do
begin
if vBit in TbitSet(ParaLongWord) then
begin
write('1');
end else
begin
write('0');
end;
end;
end;
function ****ftLeft( Left : longword; Right : Longword; ****ft : longword )
:
longword;
asm
shld eax, edx, cl
end;
function ****ftRight( Right : longword; Left : longword; ****ft : longword )
:
longword;
asm
shrd eax, edx, cl
end;
procedure Main;
var
vLeft : longword;
vRight : longword;
v****ft : longword;
vResult : longword;
begin
writeln('program started');
for v****ft := 0 to 31 do
begin
vLeft := 0;
vRight := 1 + 0 + 8 + 0 + 32 + 2147483648;
vResult := ****ftLeft( vLeft, vRight, v****ft );
Writeln( '****ftLeft vLeft: ', vLeft, ' vRight: ', vRight, ' vResult: ',
vResult );
WriteBitPattern( vLeft ); write( ' ' );
WriteBitPattern( vRight ); write( ' ' );
WriteBitPattern( vResult ); writeln;
Writeln;
end;
for v****ft := 0 to 31 do
begin
vLeft := 1 + 0 + 8 + 0 + 32 + 2147483648;
vRight := 0;
vResult := ****ftRight( vRight, vLeft, v****ft );
Writeln( '****ftRight vRight: ', vRight, ' vLeft: ', vLeft, ' vResult: ',
vResult );
WriteBitPattern( vRight ); write( ' ' );
WriteBitPattern( vLeft ); write( ' ' );
WriteBitPattern( vResult ); writeln;
Writeln;
end;
writeln('program finished');
end;
begin
try
Main;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
readln;
end.
// *** End of Code ***
Bye,
Skybuck.


|