我正在cpuid根据 AMD64 SysV ABI 实现一个在汇编中使用的函数。我需要在函数本身中使用 2 个临时寄存器:第一个用于累积返回值,第二个作为计数器。
我的功能目前看起来像:
;zero argument function
some_cpuid_fun:
push rbx
xor r10d, r10d ;counter initial value
xor r11d, r11d ;return value accumulator initial value
some_cpuid_fun_loop:
;...
cpuid
;update r10d and r11d according to the result
mov eax, r11d
pop rbx
ret
由于cpuidclobbers eax, ebx, ecx,edx我不能在不同的cpuid执行过程中使用它们。如记录在AMD64 SysV ABI:
r10 temporary register, used for passing a function’s
static chain pointer
r11 temporary register
只有一个严格的临时寄存器r11,r10似乎有不同的用途(它作为循环计数器的用途不是一个,我显然没有传递任何静态链指针)。
问题:some_cpuid_fun功能实现是否AMD64 SysV ABI兼容?如果没有如何重写它以保持与 ABI 兼容?