Page 1 of 1

Volatile registers between PB commands

Posted: Mon Dec 22, 2014 6:56 am
by wilbert
When using asm, I usually only use asm inside a procedure, no PB commands.
I'm not sure about mixing ASM with PB commands so I hope Fred or someone else knows the answer to my question.
Are eax, ecx and edx (or rax, rcx and rdx) volatile between PB commands or do they need to be preserved ?

Example ...

Code: Select all

b = 1
For i = 0 To 1000
  a = 5
  !mov eax, 5
  !mov ecx, 6
  !mov edx, 7
  a + b
Next
Is something like this always allowed (on both x86 and x64) or is it possible a PB command after the asm lines depends on one of those registers being unchanged ?

Re: Volatile registers between PB commands

Posted: Mon Dec 22, 2014 7:43 am
by STARGĂ…TE
The documentation says:
- On x86 processors, the available volatile registers are: eax, ecx and edx. All others must be always preserved.
- On x64 processors, the available volatile registers are: rax, rcx, rdx, r8, r9, xmm0, xmm1, xmm2 and xmm3. All others must be always preserved.
- To return directly the 'eax' (or 'rax' on x64) register content, just use ProcedureReturn, without any expression. It will let the 'eax' (or 'rax' on x64) register content untouched and use it as return-value.
It is also possible to use ebx, rsi, rdi and so on, but you have to back up and recover.

Re: Volatile registers between PB commands

Posted: Tue Dec 23, 2014 7:32 pm
by wilbert
Great if eax, ecx and edx can be freely used between PB commands.
I have the impression PB compiles line by line, not relying on those registers being unchanged.

What doesn't make sense to me from the docs Stargate quoted, that the xmm registers aren't marked volatile for x86 since PB doesn't use SSE at all. :?

Re: Volatile registers between PB commands

Posted: Tue Dec 23, 2014 9:24 pm
by Fred
It's a mistake, on x86 xmm0-3 are also marked as volatile