Good catch!
You are correct. The alternative to mov eax,[dbp+4] that I put in the
comment was wrong.
It was meant to be clearer for people more familiar with C/C++ than
assembler. To actually do what is needed is arguably as confusing as the
assembly language.
So the "simplified" boils down to one of these:
__declspec(naked) void* _ReturnAddress(void)
{
__asm mov eax, [ebp + 4]
return _EAX;
}
__declspec(naked) void* _ReturnAddress(void)
{
_EAX = *((unsigned *) (_EBP + 4));
return _EAX;
}
> ...don't remember enough TASM from over a decade ago, and no BASM use
> recently), but ...
If for no other reason than Call Stack and CPU View you should feel at least
somewhat comfortable with assembly. Here are a couple of links from Borland
veteran Matt Pietrek that serve it up candy coated:
Just Enough Assembly To Get By, parts 1 and 2
http://www.microsoft.com/msj/0298/hood0298.aspx
http://www.microsoft.com/msj/0698/hood0698.aspx
.. Ed
> dhoke wrote in message
> news:47822fb4$1@newsgroups.borland.com...
>
> Depending on the assembler (haven't experimented, don't remember enough
> TASM from over a decade ago, and no BASM use recently), but your alternate
> is not functionally equivalent for all assembler syntaxes, maybe not for
> B/CG products either.
>
> The original, I would expect to add 4 to BP, and retrieve the value at
> that location. Your alternate just adds 4 to BP and returns that
> (address) value, not what's located at that address...
Depending on the assembler (haven't experimented, don't remember enough TASM
from over a decade ago, and no BASM use recently), but your alternate is not
functionally equivalent for all assembler syntaxes, maybe not for B/CG
products either.
The original, I would expect to add 4 to BP, and retrieve the value at that
location.
Your alternate just adds 4 to BP and returns that (address) value, not
what's located at that address...
Yes/No?
"Ed Mulroy [TeamB]" wrote in message
news:477e3bbe$1@newsgroups.borland.com...
> Not meant as a nitpick, just an alternative.
>
> __declspec(naked) void* _ReturnAddress(void)
> {
> __asm mov eax, [ebp + 4] /* or _EAX = _EBP + 4; */
> return _EAX;
> }
>
> . Ed
>
>> Leo Havmøller wrote in message
>> news:477dd195$1@newsgroups.borland.com...
>>
>> Prototype:
>> #ifdef __cplusplus
>> extern "C"
>> #endif
>> void* _ReturnAddress(void);
>>
>> Implementation:
>> #pragma warn -8070 // W8070 Function should return a value
>> __declspec(naked) void* _ReturnAddress(void)
>> {
>> __asm mov eax, [ebp + 4]
>> __asm ret
>> }
>>
>> More info:
>> http://nedbatchelder.com/blog/20051006T065335.html
>
>
"Leo Havmøller" wrote in message
news:477caa41@newsgroups.borland.com...
> Is there a borland equivalent of Microsofts _ReturnAddress():
> http://msdn2.microsoft.com/en-us/library/64ez38eh.aspx
> Im using BDS 2006.
Prototype:
#ifdef __cplusplus
extern "C"
#endif
void* _ReturnAddress(void);
Implementation:
#pragma warn -8070 // W8070 Function should return a value
__declspec(naked) void* _ReturnAddress(void)
{
__asm mov eax, [ebp + 4]
__asm ret
}
More info:
http://nedbatchelder.com/blog/20051006T065335.html
Leo Havmøller.
Leo Havmøller wrote:
>Is there a borland equivalent of Microsofts _ReturnAddress():
>http://msdn2.microsoft.com/en-us/library/64ez38eh.aspx
>Im using BDS 2006.
I'm afraid I don't know the answer to this one, but I have a question of
my own - what on earth are you trying to do?!
(If you've got someone else's source code that uses this, I don't envy
you.)
Alan Bellingham
--
Team Browns
ACCU Conference 2008: 2-5 April 2008 - Oxford, UK