Using SHR directly in Delphi and FPC does not gives the appropriate results while converting from C to Pascal.
The >> in C while using integers is interptreted as sar in dissassemply!
The >> in C while using longwords is interptreted as shl in dissassemply!
Try implement the followng functions:
Code:
// Left shift between integers
function _SHL(const x: integer; const bits: integer): integer; assembler;
asm
// mov eax, x
// mov ecx, bits
mov ecx, edx
sal eax, cl
end;
// Left shift between longwords
function _SHLW(const x: LongWord; const bits: LongWord): LongWord;
begin
result := x shl bits;
end;
// Right shift between integers
function _SHR(const x: integer; const bits: integer): integer; assembler;
asm
mov ecx, edx
sar eax, cl
end;
{begin
result := x div (1 shl bits);
end;}
// Right shift between longwords
function _SHRW(const x: LongWord; const bits: LongWord): LongWord;
begin
result := x shr bits;
end;
Bookmarks