News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetFilePath

Started by Vortex, December 06, 2006, 06:22:51 PM

Previous topic - Next topic

Grincheux

In that case don't use PROC directive and define the procedure as a label.
What is the interest of using ESP rather than EBP in that case ?
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

Vortex

Grincheux,

Even if you replace the PROC directive with a label to identify the procedure, you need to observe the register preservation rule in the module containing the procedure. Using esp has a meaning here : by reading the value stored in esp, you don't destroy the content of this register.

lingo

#17
Lingo, here is the forum rule #2, probably you forgot it :

Quote2. The basis of the rules in the forum is respect for other members. Respect for new members who are struggling with assembler, respect for experienced members who are here to help and respect for differences between members. This cannot be done by rigid compliance to stated rules and is based on intent. Please remember that every person who posts in the forum is another human being and deserves to be treated like one.
[/color]
isslz macro
      add    ecx, 1
      cmp    byte ptr [eax+ecx],"\"
      je     K2
      cmp    byte ptr [eax+ecx], 0
      je     K3
endm

GetFilePath:
      mov    eax, [esp+1*4]
      or     ecx, -1
      mov    edx, [esp+2*4]
      movq   MM7, [eax]
      movq   [edx], MM7
      repeat 8
      isslz
      endm
K1:
      movq   MM7, [eax+ecx]
      movq   [edx+ecx], MM7
      repeat 8
      isslz
      endm
      jne    K1
K2:
      add    edx, ecx
      add    eax, ecx
      xor    ecx, ecx
      je     K1
K3:
      mov    byte ptr [edx], 0
      ret    2*4

Regards,
Lingo

Grincheux

Yes, but no need of OPTION PROLOGUE/EPILOGUE:NONE and no other code is added. When looking at


   mov      esi,DWORD PTR [esp+12]   ; source
   mov      edi,DWORD PTR [esp+16]   ; dest


we can see that a push has been added. Otherwise ESP + 12 would refer to the return address ?
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

Grincheux

To Lingo :

Very very interesting !

I imagined somthing using these kind of instructions set but I was not sure.

I understand Vortex, and he is TRUE for all of its remarks, but the finality for me is to have the quickest code. But there is a limit, at the end except the author no one else can read the source code.

But, how to progress if we don't go at the end of a problem ?

IMHO what does it mean ?
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

Grincheux

To Lingo :

K2:
      add    edx, ecx
      add    eax, ecx
      xor    ecx, ecx
      je     K1

je or jz is the same thing.

XOR ECX,ECX set the ZERO flag so JE K1 always is TRUE, what is faster JE K1 or JMP K1 ?
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

lingo

Quote....what is faster JE K1 or JMP K1 ?

"For example, a jump to a jump should be replaced by a jump to the final target.
In some cases this is even possible  with conditional jumps if the condition is the same or is known."  :lol

from 22.3. Avoiding jumps (all processors)
How to optimize for the Pentium family of microprocessors by Agner Fog


hutch--



> what is faster JE K1 or JMP K1 ?

Look at how much work the instruction performs, a JE must test a flag, a JMP does not. Both types of branches slow up a pipeline and this factor alone may mask any timing difference between the two but a JMP does less.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Grincheux,

With the condition that you introduce the procedure with a unique label identifier, you can remove the OPTION PROLOGUE/EPILOGUE:NONE statements if you wish. If you merge your main module with the procedure then you can safely remove the push statements but that would destroy the flexibility of a standalone procedure in its own module.

Vortex

Lingo,

To refresh your memory, I would like to remind you that we had a deal : you would go in your own way and me in my way. I know, it's very difficult for you to understand that you should post your specialized codes to the algorithm section. This subforum is intended for beginners and I believe that very few people here would be interested in a super fast GetFilePath algorithm. With your manners, you are portraying a person far from professionality.

If you still have difficulties to undestand what I say, don't hesitate to send me a PM and I will reply all your questions.

Grincheux

Vortex I understand what you are saying about Lingo, I don't want to know who is right, but it seems that the algo built by Lingo is coming from the discuss we had with this topic. I am not a beginner, but I appreciate this forum, more than the one you are speaking about.

I think it is not a good thing, even for a beginner, to know that now the algo is OK but it cannot be improved because he is a beginner. I think to that in specialized forums there would be explanaition about algo. Why they have been written like this, and where did they start from.

Where is the frontier between them ? If you are a beginner today will be a beginner tomorrow ? Even if I know some parts of my job sometimes I consider I am less than a beginner that helps me to understand when I am lost.

I understand the ideas of everyone, but is it MASM Forum or OK CORRAL ?

Thank you Lingo and Vortex, somewhere everyone can advance and it is the most important thing.
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

Vortex

Grincheux,

The distinction is easy : I would not consider an algorithm optimized with MMX instruction is targetting this subforum. The audience of this section are members who have some basic knowledge and experience with the assembly language. The MMX stuff would rather fall to a more advanced category. Like in other fields in life, there are phases in learning assembly and this subforum is an effort to support our members who are progressing in the learning curve. The Masm32 forum provides a place where to put advanced algorithms, it's the laboratory section.

Grincheux

Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

Vortex

Another version :

.386
.model flat,stdcall
option casemap:none

.data

GFPtable db 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
           db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

.code

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

GetFilePath PROC source:DWORD,dest:DWORD

push esi
push edi
push ebp
mov esi,DWORD PTR [esp+16] ; source
mov edi,DWORD PTR [esp+20] ; dest
xor edx,edx
xor ecx,ecx
mov ebp,OFFSET GFPtable
l0:
mov eax,edx
@@:
mov cl,BYTE PTR [esi+edx]
mov BYTE PTR [edi+edx],cl
add edx,1
cmp BYTE PTR [ebp+ecx],0
je @b
cmp cl,'\'
je l0
mov BYTE PTR [edi+eax],0
pop ebp
pop edi
pop esi
ret 8

GetFilePath ENDP

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

END

[attachment deleted by admin]

Grincheux

Sorry, but I don't understand. You gave too many comments I am lost.
I don't understand the meaning of '0' and '1' into your table.
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz