• Welcome to Valhalla Legends Archive.
 

Calling API from assembler?

Started by brew, October 02, 2007, 08:19 PM

Previous topic - Next topic

brew

Quote from: Andy on October 25, 2007, 05:34 PM
and where would our bases be if not for that game? ;D
They'd still be there, they just are not belong to us.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Warrior

Quote from: Andy on October 25, 2007, 05:34 PM
Hey man, don't dis the genesis. It gave us Zero Wing, and where would our bases be if not for that game? ;D

You're correct. If not for them, I would not know that the bases were belong to them.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

squiggly

I wish I could troll as well as you guyz
- Posso usar um tradutor de lĂ­ngua, devo ser fresco agora!

Barabajagal

And then nobody would know who the Laziest Men on Mars were, so in effect, they owe their career to Genesis. Sega should tap that.

Banana fanna fo fanna

They should reissue Sega Genesis with Zero Wing soldered into the cartridge slot.

Kp

Quote from: Win32 on October 25, 2007, 08:59 AM
Personally, I never use EBP for "stack frames", it's worthless) (Note: EBP _is_ volatile)

EBP is not volatile.  You must preserve the previous value.  You may get away with treating it as volatile if the caller happens not to need it after the call.  Stack frames are very nice for debugging, since it lets the debugger generate a proper callstack reliably.  If you do not use stack frames, the debugger is forced to guess, and that rarely turns out well.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Win32

Quote
EBP is not volatile.  You must preserve the previous value.  You may get away with treating it as volatile if the caller happens not to need it after the call.  Stack frames are very nice for debugging, since it lets the debugger generate a proper callstack reliably.  If you do not use stack frames, the debugger is forced to guess, and that rarely turns out well.
Ofcourse EBP is volatile, unless stack frames are actually disabled (and I would presume in the thread starter's case it is, as it is for most). I think you're confused as to what volatile means; as you say "you must preserve the previous value", hence why EBP is considered volatile across function calls.

Kp

You are using volatile to mean two completely opposite things.  First, you say:

Quote from: Win32 on October 25, 2007, 08:59 AM
* EAX, ECX, EDX are considered volatile registers in C++, thus you are free to use them in your own assembly routines without corrupting
  the caller's state (important when mixing Asm and C).
The standard calling convention for C++ on Win32 x86 says that EAX, ECX, and EDX may not be preserved by the called function.  That is, you must not rely on their value being the same after the function call as it was before the function call.

Then, you say:
Quote from: Win32 on October 25, 2007, 08:59 AM(Note: EBP _is_ volatile)

The caller normally expects ebp to be preserved across function calls, which is why it can be used as a stack frame pointer.

Finally, you say:
Quote from: Win32 on October 27, 2007, 12:43 AM
Ofcourse EBP is volatile, unless stack frames are actually disabled (and I would presume in the thread starter's case it is, as it is for most). I think you're confused as to what volatile means; as you say "you must preserve the previous value", hence why EBP is considered volatile across function calls.

So you are consistent in saying that "EBP is volatile."  You state in your first quote that EAX, ECX, and EDX are "volatile" and that you can change them freely.  However, in your third quote, you go on to agree that EBP must be preserved, which is the opposite of being able to change it freely.  So which is it?  Must EBP be preserved or can it be changed freely?  Is it volatile or not?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

brew

Just wondering, why wasn't ebx listed with win32's list of volatile registers? must it be preserved or something? I've been modifying ebx just like eax or ecx and i've had no errors.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

devcode

Quote from: brew on October 27, 2007, 06:29 PM
Just wondering, why wasn't ebx listed with win32's list of volatile registers? must it be preserved or something? I've been modifying ebx just like eax or ecx and i've had no errors.

gewgelz ftw

[MSDN]
When using __asm to write assembly language in C/C++ functions, you don't need to preserve the EAX, EBX, ECX, EDX, ESI, or EDI registers. In addition, by using EBX, ESI or EDI in inline assembly code, you force the compiler to save and restore those registers in the function prologue and epilogue.
[/MSDN]

Win32

Quote
The standard calling convention for C++ on Win32 x86 says that EAX, ECX, and EDX may not be preserved by the called function.  That is, you must not rely on their value being the same after the function call as it was before the function call.
Yes, my bad on that behalf. Non-volatile*


Quote
The caller normally expects ebp to be preserved across function calls, which is why it can be used as a stack frame pointer.
Hence why I said volatile, but I understand why you say because of my mistake in the previous :)


Quote
Just wondering, why wasn't ebx listed with win32's list of volatile registers? must it be preserved or something? I've been modifying ebx just like eax or ecx and i've had no errors.
That would be just luck that no caller's have used EBX.

Volatile:
EBX, ESI, EDI, EBP (If using stack frames)

Non-volatile:
EAX ECX EDX


If you're writing a CPU-intensive routine that requires alot of frequently accessed data, you can also use ESP (Failure to preserve this, will just cause a myriad of problems :))

Too bad you can't use GS, as I found out the other day :(

I believe you also need to preserve some FPU flag register (if using the FPU), not sure exactly since I don't use floating-point math much.

|