var X,Y:Integer;与var X:integer;Y:integer;编译出来的二进制代码有无区别?(100分)

  • 主题发起人 主题发起人 雁孤行
  • 开始时间 开始时间
是一样的,但X,Y:INTEGER 与 Y,X:INTEGER 不一样。
当DELPHI优化编译后,对INTERGER的分配是这样的,
先分配 EAX,EDX,EBX,ECX,ESI,给前四个INTEGER变量,
然后其他的INTEGER变量用[EBP-?]的内存单元来保存

例如:
var x:Integer;
y:integer;
z:Integer;
a:Integer;
b:integer;
c:Integer;
m:Integer;
n:integer;
p:Integer;

begin

x:=1;
y:=2
z:=3
a:=4
b:=5
c:=6
m:=7
n:=8
p:=9
............
end;

编译后就是

mov eax,01
mov edx,02
mov ebx,03
mov ecx,04
mov esi,05
mov [ebp-04],06
mov [ebp-08],07
mov [ebp-0c],08
mov [ebp-10],09

分成多行与一行是一样的,但顺序不同,分配的寄存器或内存单元就不同

 
编译结果是一样的。

procedure A1;
var
I1, I2 : Integer;
begin
I1 := 10;
I2 := I1 + 1;
ShowMessage(Format('%d %d', [I1, I2]));
end;

procedure A2;
var
I1: Integer;
I2: Integer;
begin
I1 := 10;
I2 := I1 + 1;
ShowMessage(Format('%d %d', [I1, I2]));
end;

A1
00452260 55 push ebp
00452261 8BEC mov ebp, esp
00452263 83C4EC add esp, -$14
00452266 53 push ebx
00452267 56 push esi
00452268 33D2 xor edx, edx
0045226A 8955FC mov [ebp-$04], edx
0045226D 33C0 xor eax, eax
0045226F 55 push ebp
00452270 68C5224500 push $004522C5

***** TRY
|
00452275 64FF30 push dword ptr fs:[eax]
00452278 648920 mov fs:[eax], esp
0045227B BB0A000000 mov ebx, $0000000A
00452280 8D7301 lea esi, [ebx+$01]
00452283 8D45FC lea eax, [ebp-$04]
00452286 50 push eax
00452287 895DEC mov [ebp-$14], ebx
0045228A C645F000 mov byte ptr [ebp-$10], $00
0045228E 8975F4 mov [ebp-$0C], esi
00452291 C645F800 mov byte ptr [ebp-$08], $00
00452295 8D55EC lea edx, [ebp-$14]
00452298 B901000000 mov ecx, $00000001

* Possible String Reference to: '%d %d'
|
0045229D B8DC224500 mov eax, $004522DC

|
004522A2 E8896CFBFF call 00408F30
004522A7 8B45FC mov eax, [ebp-$04]

* Reference to: dialogs.ShowMessage(System.AnsiString);
| or: dialogs.ShowMessage(System.AnsiString);
| or: Dialogs.ShowMessage(System.AnsiString);
| or: Dialogs.ShowMessage(System.AnsiString)
| or: Dialogs.ShowMessage(System.AnsiString)
|
004522AA E8F590FDFF call 0042B3A4
004522AF 33C0 xor eax, eax
004522B1 5A pop edx
004522B2 59 pop ecx
004522B3 59 pop ecx
004522B4 648910 mov fs:[eax], edx

****** FINALLY
|

* Possible String Reference to: '^[嬪]?
|
004522B7 68CC224500 push $004522CC
004522BC 8D45FC lea eax, [ebp-$04]

* Reference to: system.@LStrClr(String);
| or: System..LStrClr(System.AnsiString)
|
004522BF E8701FFBFF call 00404234
004522C4 C3 ret

004522C5 E99219FBFF jmp 00403C5C
004522CA EBF0 jmp 004522BC

****** END
|
004522CC 5E pop esi
004522CD 5B pop ebx
004522CE 8BE5 mov esp, ebp
004522D0 5D pop ebp
004522D1 C3 ret


A2
004522E4 55 push ebp
004522E5 8BEC mov ebp, esp
004522E7 83C4EC add esp, -$14
004522EA 53 push ebx
004522EB 56 push esi
004522EC 33D2 xor edx, edx
004522EE 8955FC mov [ebp-$04], edx
004522F1 33C0 xor eax, eax
004522F3 55 push ebp
004522F4 6849234500 push $00452349

***** TRY
|
004522F9 64FF30 push dword ptr fs:[eax]
004522FC 648920 mov fs:[eax], esp
004522FF BB0A000000 mov ebx, $0000000A
00452304 8D7301 lea esi, [ebx+$01]
00452307 8D45FC lea eax, [ebp-$04]
0045230A 50 push eax
0045230B 895DEC mov [ebp-$14], ebx
0045230E C645F000 mov byte ptr [ebp-$10], $00
00452312 8975F4 mov [ebp-$0C], esi
00452315 C645F800 mov byte ptr [ebp-$08], $00
00452319 8D55EC lea edx, [ebp-$14]
0045231C B901000000 mov ecx, $00000001

* Possible String Reference to: '%d %d'
|
00452321 B860234500 mov eax, $00452360

|
00452326 E8056CFBFF call 00408F30
0045232B 8B45FC mov eax, [ebp-$04]

* Reference to: dialogs.ShowMessage(System.AnsiString);
| or: dialogs.ShowMessage(System.AnsiString);
| or: Dialogs.ShowMessage(System.AnsiString);
| or: Dialogs.ShowMessage(System.AnsiString)
| or: Dialogs.ShowMessage(System.AnsiString)
|
0045232E E87190FDFF call 0042B3A4
00452333 33C0 xor eax, eax
00452335 5A pop edx
00452336 59 pop ecx
00452337 59 pop ecx
00452338 648910 mov fs:[eax], edx

****** FINALLY
|

* Possible String Reference to: '^[嬪]?
|
0045233B 6850234500 push $00452350
00452340 8D45FC lea eax, [ebp-$04]

* Reference to: system.@LStrClr(String);
| or: System..LStrClr(System.AnsiString)
|
00452343 E8EC1EFBFF call 00404234
00452348 C3 ret

00452349 E90E19FBFF jmp 00403C5C
0045234E EBF0 jmp 00452340

****** END
|
00452350 5E pop esi
00452351 5B pop ebx
00452352 8BE5 mov esp, ebp
00452354 5D pop ebp
00452355 C3 ret

 
不用想都是一样的。
 
應該是沒有區別的
 
TO:ib6study
你说顺序不同得出的值就不同,我想不可能吧,你符的值还不就形同虚设啦,嗯!?
其实我想啊,应该是一样的,只是它们在内存或寄存器中的地址不同而己吧!
 
又长一见识
 
觉得没有区别
你用procedure DoNothing(a,b: String)

让Delphi自动生成 代码 (Ctrl+Shift+C) 就成了

procedure TForm1.DoNothing(a, b: String);
 
当然有区别,前者两个参数都是传址调用,后者的Y为传值调用,

(不会二者区别不知道吧?)

var X:integer;var Y:integer;的话应该一样,编译器会处理
 
多人接受答案了。
 
后退
顶部