Jump to content
Tuts 4 You
Sign in to follow this  
Guest nothing_2006

Help On The Fx Of This Code

Recommended Posts

Guest nothing_2006

i saw below code in one tutorial, but i dont understand what it means

==============

01 MOV ECX, FFFFFFFF

02 SUB EAX, EAX

03 REPNZ SCASB

04 NOT ECX

05 DEC ECX <== length

==============

the tut said it's used to calculate the length of the string/char

and ECX mean say the length

line 01: mov -1 to ECX

line 02: EAX-EAX=> ZF=1

line 03: ???????

line 04: NOT ECX

line 05: ECX=ECX-1

can anyone help...

:worthy:

Share this post


Link to post
Ziggy

You will find a help file in the MASM32 package which explains the intel opcodes

For example

REPNE/REPNZ - Repeat Not Equal / Repeat Not Zero

Usage: REPNE

REPNZ

Modifies flags: None

Repeats execution of string instructions while CX != 0 and the Zero

Flag is clear. CX is decremented and the Zero Flag tested after

each string operation. The combination of a repeat prefix and a

segment override on processors other than the 386 may result in

errors if an interrupt occurs before CX=0.

Clocks Size

Operands 808x 286 386 486 Bytes

none 2 2 2 1

F2 A6 REPNE CMPS m8,m8 Find matching bytes in ES:[(E)DI] and DS:[(E)SI]

F2 A7 REPNE CMPS m16,m16 Find matching words in ES:[(E)DI] and DS:[(E)SI]

F2 A7 REPNE CMPS m32,m32 Find matching doublewords in ES:[(E)DI] and DS:[(E)SI]

F2 AE REPNE SCAS m8 Find AL, starting at ES:[(E)DI]

F2 AF REPNE SCAS m16 Find AX, starting at ES:[(E)DI]

F2 AF REPNE SCAS m32 Find EAX, starting at ES:[(E)DI]

It's worthwhile to install the MASM package and extract the opcode helpfile. Helps answer questions like this.

EDIT : I've attached the full set of MASM help files.

In this case the REPNZ will keep searching the bytes in the string referenced by EDI (and decrementing ECX) until it finds a zero value. Not of ECX then has the string length +1.

Ziggy

MASM_HelpFiles.zip

Share this post


Link to post
Teddy Rogers

A nice website to check out if you come across instructions you are unsure about:

http://faydoc.tripod.com/cpu/index_r.htm

Hope it helps you... :)

Ted.

Share this post


Link to post
Guest nothing_2006

thanks both of you anyway :thumbsup:

and your suggestions are very useful

i 've found out it's becase of the tutorial,

there is something missed in the code,

and here is the full code i found finally

MOV EDX,EAX

MOV ECX,-1

SUB EAX,EAX

REPNE SCAS BYTE PTR ES:[EDI]

NOT ECX

DEC ECX

:hug:

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...