Results 1 to 10 of 25

Thread: C to Pascal conversion hq2x

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #21

    C to Pascal conversion hq2x

    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;
    Last edited by Jimmy Valavanis; 30-03-2012 at 04:10 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •