JJ,
Here is your Christmas present for the year before last or perhaps the year before that. Each rerun of the pair, SaveEmAll and RestoreEmAll will overwrite the previous result.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include64\masm64rt.inc
; --------------------------------------------------
AllocRegSpace MACRO
IsLoaded@@@@ equ (1)
.data?
.rax dq ?
.rbx dq ?
.rcx dq ?
.rdx dq ?
.rsi dq ?
.rdi dq ?
.r8 dq ?
.r9 dq ?
.r10 dq ?
.r11 dq ?
.r12 dq ?
.r13 dq ?
.r14 dq ?
.r15 dq ?
.rbp dq ?
.rsp dq ?
.code
ENDM
; --------------------------------------------------
SaveEmAll MACRO
IFNDEF IsLoaded@@@@
AllocRegSpace
ENDIF
mov .rax, rax
mov .rbx, rbx
mov .rcx, rcx
mov .rdx, rdx
mov .rsi, rsi
mov .rdi, rdi
mov .r8, r8
mov .r9, r9
mov .r10, r10
mov .r11, r11
mov .r12, r12
mov .r13, r13
mov .r14, r14
mov .r15, r15
mov .rbp, rbp
mov .rsp, rsp
ENDM
; --------------------------------------------------
RestoreEmAll MACRO
IFNDEF IsLoaded@@@@
echo Register Space Not Allocated
exitm
.err
ENDIF
mov rax, .rax
mov rbx, .rbx
mov rcx, .rcx
mov rdx, .rdx
mov rsi, .rsi
mov rdi, .rdi
mov r8, .r8
mov r9, .r9
mov r10, .r10
mov r11, .r11
mov r12, .r12
mov r13, .r13
mov r14, .r14
mov r15, .r15
mov rbp, .rbp
mov rsp, .rsp
ENDM
; --------------------------------------------------
.code
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
entry_point proc
SaveEmAll
RestoreEmAll
SaveEmAll
conout str$(rax),lf
conout str$(rbx),lf
conout str$(rcx),lf
conout str$(rdx),lf
conout str$(rsi),lf
conout str$(rdi),lf
conout str$(r8),lf
conout str$(r9),lf
conout str$(r10),lf
conout str$(r11),lf
conout str$(r12),lf
conout str$(r13),lf
conout str$(r14),lf
conout str$(r15),lf
conout str$(rbp),lf
conout str$(rsp),lf,lf,lf
mov rax, 1234
mov rbx, 5678
mov rcx, 9012
mov rdx, 3456 ; change register content
mov rsi, 7890
mov rdi, 1234
add rsp, rbp
rol rdx, 4
RestoreEmAll
conout str$(rax),lf
conout str$(rbx),lf
conout str$(rcx),lf
conout str$(rdx),lf
conout str$(rsi),lf
conout str$(rdi),lf
conout str$(r8),lf
conout str$(r9),lf
conout str$(r10),lf
conout str$(r11),lf
conout str$(r12),lf
conout str$(r13),lf
conout str$(r14),lf
conout str$(r15),lf
conout str$(rbp),lf
conout str$(rsp),lf,lf,lf
waitkey
.exit
entry_point endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end