Volatile registers between PB commands

Bare metal programming in PureBasic, for experienced users
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Volatile registers between PB commands

Post 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 ?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
STARGÅTE
Addict
Addict
Posts: 2084
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Volatile registers between PB commands

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Volatile registers between PB commands

Post 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. :?
Windows (x64)
Raspberry Pi OS (Arm64)
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Volatile registers between PB commands

Post by Fred »

It's a mistake, on x86 xmm0-3 are also marked as volatile
Post Reply