[fpc-pascal] rotating bits

Tomas Hajny XHajT03 at mbox.vol.cz
Wed May 24 15:26:58 CEST 2006


đŁÔŇ ëĎÓÁŇĹ×ÓËÉĘ wrote:
>> On 24 mei 2006, at 10:56, đŁÔŇ ëĎÓÁŇĹ×ÓËÉĘ wrote:
>> > Is there high level operator/(inline)function for rotating bits?
>> No.
>> > Am I supposed to implement rotating bits (like ror/rol in i386 asm)
>> > by inline assembler or some ugly workarounds (shifts and or-s)?
>> Yes. I think there's already a feature request to provide these
>> operations, but no one worked on it yet.
>
> Why don't use this code?
 .
 .
>  function brol(b: byte; c: byte): byte; assembler; inline;
>    asm
>    movb  b,%al
>    movb  c,%cl
>    rolb  %cl,%al
>    movb  %al,result
>    end ['al','cl'];
 .
 .

With register calling convention (which is the default calling convention
in FPC 2.x), it can be reduced just to:

function brol(b: byte; c: byte): byte; assembler; inline;
asm
  rolb  %cl,%al
end;


(and similarly for all the other functions). The first parameter goes to
eax, the second to ecx, and the result is supposed to be in eax again.

Tomas




More information about the fpc-pascal mailing list