How convert this C code to PB?

Just starting out? Need help? Post your questions and find answers here.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: How convert this C code to PB?

Post by idle »

sorry it's a x64 bit macro only :oops:
Windows 11, Manjaro, Raspberry Pi OS
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How convert this C code to PB?

Post by wilbert »

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))
By the way, you shouldn't use
Dim temp.c(7)
It fails when compiled in unicode mode.
In this case you need the .b or .a type.
Windows (x64)
Raspberry Pi OS (Arm64)
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: How convert this C code to PB?

Post by sec »

wilbert wrote:

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))
By the way, you shouldn't use
Dim temp.c(7)
It fails when compiled in unicode mode.
In this case you need the .b or .a type.
Super man :D

Thanks, almost done my convert.
Post Reply