When you alter the stack with pushing and popping registers, that messes up references to local variables like [p.v_bbb]
What I'm currently using is an integer variable to store the register. This works fine.
The same way you can preserve
rsi/esi and
rdi/edi if you need even more registers.
Using
rbp/ebp as an extra register causes problems with the debugger.
Code:
Procedure myproc(bbb.l)
Protected.i reg_bx
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
!mov [p.v_reg_bx], rbx
CompilerElse
!mov [p.v_reg_bx], ebx
CompilerEndIf
;bbb + 1
!mov ebx, dword [p.v_bbb]
!inc ebx
!mov dword [p.v_bbb], ebx
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
!mov rbx, [p.v_reg_bx]
CompilerElse
!mov ebx, [p.v_reg_bx]
CompilerEndIf
ProcedureReturn bbb
EndProcedure
n = myproc(5) ;should return 6
Debug n