Re: How convert this C code to PB?
Posted: Wed Sep 04, 2013 7:17 am
sorry it's a x64 bit macro only 

http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Procedure.q Rotl64(val.q, n)
!mov ecx, [p.v_n]
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
!mov rax, [p.v_val]
!rol rax, cl
CompilerElse
!btr ecx, 5
!jc rotl64_1
!mov eax, [p.v_val]
!mov edx, [p.v_val + 4]
!jmp rotl64_2
!rotl64_1:
!mov edx, [p.v_val]
!mov eax, [p.v_val + 4]
!rotl64_2:
!push ebx
!mov ebx, eax
!shld eax, edx, cl
!shld edx, ebx, cl
!pop ebx
CompilerEndIf
ProcedureReturn
EndProcedure
Debug Bin(Rotl64(%1101, 61))
Super manwilbert wrote:By the way, you shouldn't useCode: Select all
Procedure.q Rotl64(val.q, n) !mov ecx, [p.v_n] CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 !mov rax, [p.v_val] !rol rax, cl CompilerElse !btr ecx, 5 !jc rotl64_1 !mov eax, [p.v_val] !mov edx, [p.v_val + 4] !jmp rotl64_2 !rotl64_1: !mov edx, [p.v_val] !mov eax, [p.v_val + 4] !rotl64_2: !push ebx !mov ebx, eax !shld eax, edx, cl !shld edx, ebx, cl !pop ebx CompilerEndIf ProcedureReturn EndProcedure Debug Bin(Rotl64(%1101, 61))
Dim temp.c(7)
It fails when compiled in unicode mode.
In this case you need the .b or .a type.