Archive: Preserving registers?


Preserving registers?
When writing a reusable macro, I was looking at how to preserve and restore reguisters.

The DotNET macro on the wiki has this at the beginning:

Push $0
Push $1
Push $2
Push $3
Push $4
Push $5
Push $6 ;backup of intsalled ver
Push $7 ;backup of DoNetReqVer

And this at the end:

Pop $0
Pop $1
Pop $2
Pop $3
Pop $4
Pop $5
Pop $6 ;backup of intsalled ver
Pop $7 ;backup of DoNetReqVer

Wouldn't this restore the registers completely transposed?

I was looking at the LogicLib.nsh, and it seems a lot more readable. I was wondering about how this works:

!macro _== _a _b _t _f
StrCmp `${_a}` `${_b}` `${_t}` `${_f}`
!macroend

What would happen if I already had a _a defined in my script? Or if I tried to define _a after using that macro? Would there be a conflict?

Is there special meaning to the leading underscore, or is that just to minimize the chance of a conflict?

I like the idea of just prefixing defines with the name of the script file. Kind of like a namespace.


Indeed, that piece of code is just wrong. It switches all of the variables after the macro call and doesn't properly restores them. $0 will be $7, $1 will be $6 and so on. I've fixed the Wiki page.

As for LogicLib, macro's definitions override global definitions so it doesn't have a problem with an existing definition named _a.