. .

1. , "first " "second " .

IDEAL

P586

MODEL FLAT

Extrn ExitProcess:proc

DATASEG

str1 db 'first ', 0

str2 db 'second', 0

rez db (rez-str1-1) dup (?)

CODESEG

begin:

push offset str1 offset str2 offset rez ;

call strcat ;

call ExitProcess

proc strcat;

0

EBP

push ebp;

4

EIP

mov ebp, esp;

8

REZ

Push eax ebx ecx;

12

STR2

; for (I=0; str1[I]; I++) rez[I]=str1[i];

16

STR1

Mov EAX, [EBP+16];

Mov EBX, [EBP+8];

For1:

Mov CL, [EAX]

Test Cl, cl

Je break1

Mov [EBX], cl

Inc eax

Inc ebx

Jmp For1

Break1:

Mov EAX, [ebp+12]

For2:

Mov CL, [EAX]

Mov [EBX], cl

Test Cl, cl

Je break2

Inc eax

Inc ebx

Jmp For2

Break2:

Pop ecx ebx eax ebp

Ret 12

Endp

End begin

( 0). . (str1, str2) (rez) . -

, .

2. , .

ideal

p386

model flat

extrn ExitProcess:proc

dataseg

x dd 1,2,3,4,5,6


AL - -
AX - -
EAX -
EDX, EAX - 2 v
3. T "v" . L 0, , 1 1 .
ideal
p686
model flat
extrn ExitProcess:proc
dataseg
x dd 1000 dup (0ffffffffh)
n dd (n-x)/4
y dd 1000 dup (0ffffffffh)
res dd ?
t1 dd ?
t2 dd ?
codeseg
begin:
push [n] offset x offset y
rdtsc
mov ecx,eax
call m_cmp
mov [res], eax
rdtsc
sub eax, ecx
mov [t1], eax
push [n] offset x offset y
rdtsc
mov ecx,eax
call m_cmp
mov [res], eax
rdtsc
sub eax, ecx
mov [t1], eax
push [n] offset x offset y
rdtsc
mov ecx,eax
call m_cmp1
mov [res], eax
rdtsc
sub eax,ecx
mov [t2], eax
call ExitProcess
;for (i=n-1; i>=0; i--){ ebp 0
; if (x[i]>y[i]) return -1; eip 4
; if (x[i]<y[i]) return 1; y 8
;} x 12
;return 0; n 16
proc m_cmp
push ebp;
mov ebp, esp;
Push ebx ecx edx
mov ecx, [ebp+16]; n
mov eax, [ebp+12]; &x
mov ebx, [ebp+8] ; &y
fori:
mov edx, [eax+ecx*4-4]
cmp edx, [ebx+ecx*4-4]
jb short m1; x[i]< y[i]
ja short m2; x[i]> y[i]
loop fori
sub eax, eax
m1:
mov eax, -1
jmp short m3
m2:
mov eax, 1
m3:
pop edx ecx ebx ebp
Ret 12
Endp
proc m_cmp1
push ebp;
mov ebp, esp;
Push ecx esi edi
mov ecx, [ebp+16]; n
mov esi, [ebp+12]; &x
lea esi, [esi + ecx*4-4]
mov edi, [ebp+8] ; &y


lea edi, [edi + ecx*4-4]
std
repe cmpsd
jb short m11; x[i]< y[i]
ja short m12; x[i]> y[i]
sub eax, eax
m11:
mov eax, -1
jmp short m13
m12:
mov eax, 1
m13:
cld
pop edi esi ecx ebp
Ret 12
Endp
end begin
, v 𦪸, v. . T , v v v .
+ v v v . RDTSC (Read Time-stamp counter) - v , PENTIUM MMX EAX
+v , , CPUIDCPU Identification
, , , , . - v EAX ( 11.3). CPUID v .
T 11.3

Tv v
Tvv v
EAX = 0
EAX , (v 2)
EBX, EDX, ECX - PENTIUM GenuineIntel : EBX ?756e6547h (* "Genu", G BL *)
EDX ?49656e69h (* "ineI", i -DL *)
ECX ?6c65746eh (* "ntel", n CL *)
EAX = 1
EAX (, , , step)
EBX -
ECX-
EDX
EAX = 2
EAX
EBX -
ECX-
EDX

v EDX:
23 MMX ;
18 96 v v .
4 RDTSC
4. T , 1, RDTSC 0 .
ideal
p686
model flat
extrn ExitProcess:proc
dataseg
res dd ?
codeseg
begin:
call IsReadCount
mov [res], eax
call ExitProcess
proc IsReadCount
mov eax, 1
cpuid
mov eax, 1
test edx, 1 shl 4
jnz short m1
sub eax, eax
m1:
Ret
Endp
end begin