I\'m a CS student writing in Intel x86-64 assembly, compiling with nasm, and running on an Core i7 processor with Ubuntu 12.04 as the guest OS. Does anyone hav
The xsave/xrstor/xsaveopt instructions are used to perform a full save/restore of the extended state in the processor to/from memory. Similar to fxsave/fxrstor, it saves/restores fpu state st[0..7], xmm[0..7], mxcsr, etc... in addition to supporting ymm[0..15] and future extensions (zmm[0..31]). The actual values saved, and the data layout are enumerated via the relevant cpuid leaves. The use is generally operating system context switching. The programmer reference describes how to use them correctly.
For general userspace register save/restore, the assembler usually has a facility for saving/restoring a set of registers.
For example...
foo PROC USES eax,ebx,ecx
xor ebx, ebx
loop:
mov eax, [esi + ebx*4]
mov [edi + ebx*4], eax
inc ebx
dec ecx
jnz loop
ret
foo ENDP
%macro mpush 1-*
%rep %0
push %1
%rotate 1
%endrep
%endmacro
%macro mpop 1-*
%rep %0
%rotate -1
pop %1
%endrep
%endmacro
foo:
mpush rax,rbx,rcx
xor rbx, rbx
loop:
mov rax, [rsi + rbx*8]
mov [rdi + rbx*8], rax
inc rbx
dec rcx
jnz loop
mpop rax,rbx,rcx
ret
In ia-32, there is a pushad to save all the general purpose registers, but with amd64 you need to have corresponding push/pop pairs for each of the registers you use.