Page 2 of 2

Re: How convert this C code to PB?

Posted: Wed Sep 04, 2013 7:17 am
by idle
sorry it's a x64 bit macro only :oops:

Re: How convert this C code to PB?

Posted: Wed Sep 04, 2013 9:20 am
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.

Re: How convert this C code to PB?

Posted: Wed Sep 04, 2013 10:57 am
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.