PureBasic Forum
http://forums.purebasic.com/english/

Volatile registers between PB commands
http://forums.purebasic.com/english/viewtopic.php?f=35&t=61286
Page 1 of 1

Author:  wilbert [ Mon Dec 22, 2014 6:56 am ]
Post subject:  Volatile registers between PB commands

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:
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 ?

Author:  STARGĂ…TE [ Mon Dec 22, 2014 7:43 am ]
Post subject:  Re: Volatile registers between PB commands

The documentation says:
Quote:
- 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.

Author:  wilbert [ Tue Dec 23, 2014 7:32 pm ]
Post subject:  Re: Volatile registers between PB commands

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. :?

Author:  Fred [ Tue Dec 23, 2014 9:24 pm ]
Post subject:  Re: Volatile registers between PB commands

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

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/