Re: C'Mon, this *isn't* Rocket Science
- From: randyhyde@xxxxxxxxxxxxx
- Date: 28 Jul 2005 19:27:14 -0700
hutch-- wrote:
> The semantic shift here does not solve the problem by twiddling the
> context of te word "preserve", on x86 hardware, preserve a register
> means save it somewhere and "restore" a register means copying back
> that value to the changed register.
No, it does not. See my other post.
Saving and restoring registers is *not* the same as preserving those
registers. Saving and restoring is an *active* operation, preserving
may be *passive*.
>
> Now this attempt at a semantic shift leads to direct ambiguity with
> what is involved with register preservation. By the definition being
> peddled here "preserve" is ambiguous as in the following examples.
>
> Item proc args etc ....
> ; code
> ret
> item endp
>
> item2 proc args etc ....
> push ebx
> push esi
> push edi
> ; code
> pop edi
> pop esi
> pop ebx
> ret
> item2 endp
>
> Which one has "preserved" registers and which one has not ?
The one that ensures that the registers maintain all the same values on
exit that they had on entry. That could be both of the above, neither
of the above, or all of the above depending entirely on the code and
which registers you need preserved.
>
> Now if someone could help f0dder change his definition in two things he
> could resolve the problem where he has kept misadvising learner
> programmers for years.
I'm afraid I have to agree with Donkey and f0dder on this one. You're
the one who needs to use the definition of "preserve" in it's more
traditional manner. Please see my other post for details.
>
> 1. Return to the operating system UNCHANGED the registers it expects to
> remain unchanged (ebx esp ebp esi edi).
Their values are preserved.
> If this means having to
> PRESERVE them so you can use them, then fine.
What you really mean to say here is "if this means having to save and
restore them..."
Preserve is a *passive* term. You can preserve things by doing nothing
(assuming no other changes are made to those things). Save and restore
is an *active* term. You must do something to *save* the registers
(e.g., push their values) and you must do something to *restore* their
values (e.g., pop them). You're simply confusing the term "preserve"
with "save and restore".
>
> 2. FORGET CALLBACKS, they are no difference to any other interaction
> with the operating system, WndProc, DlgProc, subclasses, Hook
> procedures and the inverse when calling an API function.
This is absolutely correct.
>
> The only requirement is that you preserve registers on the basis of
> NEED ALONE.
Well, that statement is ambiguous.
Again, if you do nothing to a register in a procedure, you've preserved
it's value.
To preserve a register whose value you've changed in a procedure,
you're probably going to need to save and restore that value
(technically, you don't need to save it if you know what it's value
always is on entry, you can simply restore that known value prior to
leaving; for example, "preserving" the direction flag my simply consist
of a CLD instruction as the Intel ABI suggests that you keep the
direction flag clear *except* in the code sequence where you need it
set).
>
> Prefixing the following nonsense with a set of conditions does not
> solve the problem.
>
> > *) in callback routines, such as wndprocs, you must preserve EBX, ESI,
> EDI, EBP, ESP.
>
> The difference is the imperative "must" which is different to "can" or
> "might" or on the basis of "need alone", it asserts an imperative based
> on the form of a callback and this is nonsense.
Agreed. Register preservation (under Intel ABI) is mostly free of
context. Doesn't matter what kind of routine it is (well, interrupt
service routines *do* matter, but you generally don't get to write
those yourself under Windows).
But that doesn't change the fact that you're confusing the term
"preserve" with "save and restore".
Cheers,
Randy Hyde
.
- Follow-Ups:
- Re: C'Mon, this *isn't* Rocket Science
- From: Gmork
- Re: C'Mon, this *isn't* Rocket Science
- References:
- C'Mon, this *isn't* Rocket Science
- From: randyhyde
- Re: C'Mon, this *isn't* Rocket Science
- From: hutch--
- C'Mon, this *isn't* Rocket Science
- Prev by Date: Re: Donkey Strikes Again !
- Next by Date: Re: Donkey Strikes Again !
- Previous by thread: Re: C'Mon, this *isn't* Rocket Science
- Next by thread: Re: C'Mon, this *isn't* Rocket Science
- Index(es):
Relevant Pages
|
Loading