-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRotatBit.pas
56 lines (45 loc) · 1.33 KB
/
RotatBit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
unit RotatBit;
interface
function Rol32(i: integer; RotateBy: integer): integer;
function Ror32(i: integer; RotateBy: integer): integer;
function Rol16(i: Smallint; RotateBy: Smallint): Smallint;
function Ror16(i: Smallint; RotateBy: Smallint): Smallint;
function Rol8(i: Byte; RotateBy: Byte): Byte;
function Ror8(i: Byte; RotateBy: Byte): Byte;
implementation
//I really dislike the fact that Delphi, does not know inline routines.
//I should have started with C.
//btw This can be solved with the {$I filename} compiler-directive
//but this gives real UGLY code and I hate UgLy CodE.
function Rol32(i: integer; RotateBy: integer): integer; register;
asm
mov ECX, EDX {# of bits to rotate in CL}
rol EAX, CL {Result In EAX}
end;
function Ror32(i: integer; RotateBy: integer): integer; register;
asm
mov ECX, EDX {# of bits to rotate in CL}
ror EAX, CL {Result In EAX}
end;
function Rol16(i: Smallint; RotateBy: Smallint): Smallint; register;
asm
mov ECX, EDX {# of bits to rotate in CL}
rol AX,CL {Result In EAX}
end;
function Ror16(i: Smallint; RotateBy: Smallint): Smallint; register;
asm
mov ECX, EDX
ror AX,CL
end;
function Rol8(i: Byte; RotateBy: Byte): Byte; register;
asm
mov ECX, EDX
rol AL,CL
end;
function Ror8(i: Byte; RotateBy: Byte): Byte; register;
asm
mov ECX, EDX
ror AL,CL
end;
initialization
end.