SysUtils, Windows;
I, J, K, M, N: Integer;
begin
// the BASE arithmetic ...
M := 1;
N := 2;
for I := 0 to 5000 do
begin
for J := 0 to 5000 do
begin
M := M + N;
N := M - N;
M := M - N;
end;
end;
K := GetTickCount - K;
Writeln(K, ';', M, ';', N);
ReadLn;
M := 1;
N := 2;
asm // EAX: 循环计数; ECX: I; EDX: J; EBX: M; EDI: N
PUSH EBX
PUSH EDI
MOV EBX, M
MOV EDI, N
MOV ECX, 0
@Loop1: CMP ECX, EAX
JA @Loop1End
MOV EDX, 0
@Loop2: CMP EDX, EAX
JA @Loop2End
XCHG EBX, EDI
INC EDX
JMP @Loop2
@Loop2End: INC ECX
JMP @Loop1
MOV N, EDI
POP EDI
POP EBX
end;
K := GetTickCount - K;
Writeln(K, ';', M, ';', N);
ReadLn;
M := 1;
N := 2;
for I := 0 to 5000 do
begin
for J := 0 to 5000 do
begin
M := M xor N;
N := N xor M;
M := M xor N;
end;
end;
K := GetTickCount - K;
Writeln(K, ';', M, ';', N);
ReadLn;
end.
#include <windows.h>
{
int I, J, K, M, N;
M = 1;
N = 2;
K = GetTickCount();
for (I = 0; I <= 5000; I++)
{
for (J = 0; J <= 5000; J++)
{
M = M + N;
N = M - N;
M = M - N;
}
}
K = GetTickCount() - K;
}