Page 1 of 1

Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 4:11 pm
by Mr52
;Thanks to mjrod5 for Fasm Example
;Mr52
Procedure GetSelfName()
!MOV eax, [fs:0x30]
!MOV eax, [eax+0x0C]
!MOV eax, [eax+0x14]
!MOV ecx, [eax+0x24] ;Length
!MOV eax, [eax+0x28] ;Buffer(Unicode btw)
ProcedureReturn
EndProcedure

It returns the Application Name like in VB App.Exename :)

it doesnt return the Path

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 4:30 pm
by ts-soft
thx,
easier to use:

Code: Select all

Procedure _GetSelfName()
  !MOV eax, [fs:0x30]
  !MOV eax, [eax+0x0C]
  !MOV eax, [eax+0x14]
  !MOV ecx, [eax+0x24] ;Length
  !MOV eax, [eax+0x28] ;Buffer(Unicode btw)
  ProcedureReturn
EndProcedure

Procedure.s GetSelfName()
  ProcedureReturn PeekS(_GetSelfName(), -1, #PB_Unicode)
EndProcedure

Debug GetSelfName()

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 5:15 pm
by Mr52
whats the difference between mine and urs ?

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 5:22 pm
by ts-soft
It returns the string in the right format and not only a pointer to a unicode buffer :wink:

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 5:40 pm
by luis
Am I missing something ?

Code: Select all

Debug GetFilePart(ProgramFilename())
We can do natively already.

But thanx for the asm example anyway :)

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 5:49 pm
by Nituvious
That's very cool. Thanks for sharing, love to see ASM code to learn from!

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 6:01 pm
by Mr52
oh @ts-soft thanks got it :P

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 6:20 pm
by ar-s
Interesting code thanks.

The native PB command is still faster for me.
Is that a normal thing ?

Code: Select all

	Procedure _GetSelfName() 
    !MOV eax, [fs:0x30] 
    !MOV eax, [eax+0x0C] 
    !MOV eax, [eax+0x14] 
    !MOV ecx, [eax+0x24] ;Length 
    !MOV eax, [eax+0x28] ;Buffer(Unicode btw) 
    ProcedureReturn 
  EndProcedure 
  
  
  t=ElapsedMilliseconds()
  mot$=""
  For i = 1 To 10000
    mot$+PeekS(_GetSelfName(), -1, #PB_Unicode)
  Next i
  
  temps = ElapsedMilliseconds()-t
  MessageRequester("t","ASM : "+Str(temps))
    
  
  
  t=ElapsedMilliseconds()
  mot$=""
  For i = 1 To 10000
    mot$+GetFilePart(ProgramFilename())
  Next i
  
  temps = ElapsedMilliseconds()-t
  MessageRequester("t","PB : "+Str(temps))

Re: Get Current Application Name [Inline ASM]

Posted: Sat Jun 25, 2011 6:58 pm
by luis
@ar-s

With your code you are timing the string concatenation routines of PB, not the execution time of the two functions :D

When you do benchmarks, you must pay attention to any possible overhead you are introducing with your test code.
In your case it's all overhead. Change the mot$+ with mot$= to confirm that.

Anyway, how many times do you have to ask for that kind of info in your program ? Probably one.

So one millisecond or 100 milliseconds I would say it's not much important.

Re: Get Current Application Name [Inline ASM]

Posted: Thu Jun 30, 2011 3:17 am
by em_uk

Code: Select all

Procedure _GetSelfName()
  !MOV eax, [fs:0x30]
  !MOV eax, [eax+0x0C]
  !MOV eax, [eax+0x14]
  !MOV ecx, [eax+0x24] ;Length
  !MOV eax, [eax+0x28] ;Buffer(Unicode btw)
  ProcedureReturn
EndProcedure


t=ElapsedMilliseconds()
mot$=""
For i = 1 To 10000
  mot$=PeekS(_GetSelfName(), -1, #PB_Unicode)
Next i

Debug mot$

temps = ElapsedMilliseconds()-t
MessageRequester("t","ASM : "+Str(temps))



t=ElapsedMilliseconds()
mot$=""
For i = 1 To 10000
  mot$=GetFilePart(ProgramFilename())
Next i

Debug mot$

temps = ElapsedMilliseconds()-t
MessageRequester("t","PB : "+Str(temps))
Completes instantly on my machine. Both results 0.