PDA

View Full Version : درباره BASM در دلفی چی می دونید ؟



میتی دات نت
یک شنبه 08 شهریور 1383, 17:09 عصر
به نام خدا

ضمن تبریک سالروز ولادت آقا امیرالمومنین (علیه السلام) به همه دوستان

می خواستم یه اطلاعاتی درباره BASM در دلفی به من بدهید که چیست و به چه دردی می خورد و چند منبع مطالعاتی و...

البته من خودم تازه آشنا شده ام
:?: :?: :?: :?: :?: :?:

مهدی کرامتی
یک شنبه 08 شهریور 1383, 18:07 عصر
نقل قول از راهنمای دلفی:
<span dir=ltr>You can write complete procedures and functions using inline assembly language code, without including a begin...end statement. For example,

function LongMul(X, Y: Integer): Longint;
asm
MOV EAX,X
IMUL Y
end;

The compiler performs several optimizations on these routines:

No code is generated to copy value parameters into local variables. This affects all string-type value parameters and other value parameters whose size isn't 1, 2, or 4 bytes. Within the routine, such parameters must be treated as if they were var parameters.
Unless a function returns a string, variant, or interface reference, the compiler doesn't allocate a function result variable; a reference to the @Result symbol is an error. For strings, variants, and interfaces, the caller always allocates an @Result pointer.

The compiler only generates stack frames for nested routines, for routines that have local parameters, or for routines that have parameters on the stack.
The automatically generated entry and exit code for the routine looks like this:

PUSH EBP ;Present if Locals &lt;> 0 or Params &lt;> 0
MOV EBP,ESP ;Present if Locals &lt;> 0 or Params &lt;> 0
SUB ESP,Locals ;Present if Locals &lt;> 0
...
MOV ESP,EBP ;Present if Locals &lt;> 0
POP EBP ;Present if Locals &lt;> 0 or Params &lt;> 0
RET Params ;Always present

If locals include variants, long strings, or interfaces, they are initialized to zero but not finalized.
Locals is the size of the local variables and Params is the size of the parameters. If both Locals and Params are zero, there is no entry code, and the exit code consists simply of a RET instruction.

Assembly language functions return their results as follows.

Ordinal values are returned in AL (8-bit values), AX (16-bit values), or EAX (32-bit values).
Real values are returned in ST(0) on the coprocessor's register stack. (Currency values are scaled by 10000.)
Pointers, including long strings, are returned in EAX.
Short strings and variants are returned in the temporary location pointed to by @Result.</span>