
How convert this C code to PB?
Re: How convert this C code to PB?
sorry it's a x64 bit macro only 

Windows 11, Manjaro, Raspberry Pi OS


Re: How convert this C code to PB?
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))
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)
Raspberry Pi OS (Arm64)
-
- 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?
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.

Thanks, almost done my convert.