flat assembler
Message board for the users of flat assembler.

Index > Main > invoke

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 11 May 2011, 09:53
Code:
invoke Z, [Y], 'AAAA'

Fasm does compile, result :

 call x
      db 41h
      db 41 h
     db 41 h
     db 41 h
     db 0                ;why this "db 0"
x:        push dword [Y]
      call [Z]
    

where this "call" comes from ?
I don't see anything in the macro "invoke" ?
thank you all

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 May 2011, 09:53
View user's profile Send private message Send e-mail Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 11 May 2011, 10:05
It is because you are using string constant as an argument. Invoke macro defines the string at the current address and then calls x in order to determine what this address is and to pass it to the function invoked.
IMHO - using string constants as an arguments is very bad programming habit.
HLLs implements this kind of features in totally different way.
Post 11 May 2011, 10:05
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 11 May 2011, 10:17
Quote:

Invoke macro defines the string at the current address....

thank you JohnFound for your repy

I don't see anything about this inside invoke macro.
just ... "reverse pusd arg"
Where the code of this "call" comes from ?
Quote:

is very bad programming habit...
why ?
what is the good way to do that ?

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 May 2011, 10:17
View user's profile Send private message Send e-mail Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 11 May 2011, 10:42
There should be redefined "pushd" instruction somewhere. Tomasz likes this kind of tricks. Razz

For me, the good way to make it is to define explicitly the constant somewhere and then to use it's address in the call.
Code:
; in the code section:
  invoke SomeFunction, MyString

; in the data section:
MyString db 'Something', 0
    


The only drawback of this approach is that string definition and string use are placed far from each other.
That is why I created "globals.inc" library to define the data at proper place. In this case the code will looks like this:
Code:
; in the code section:
MyString text 'Something'
  invoke SomeFunction, MyString
    
Post 11 May 2011, 10:42
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 11 May 2011, 11:00
Quote:

Tomasz likes this kind of tricks. Wink
ok, understood.
thank you for your help
PS:
it was about "ExAllocatePoolWithTag"
this works fine too :
Code:
invoke        ExAllocatePoolWithTag, NonPagedPool, eax, dword "ABCD"
;not "x" but dword "x"
    
Have a good day.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 May 2011, 11:00
View user's profile Send private message Send e-mail Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 11 May 2011, 13:10
Code:
invoke       Z, [Y], 'AAAA'

Fasm does compile, result :

 call x
      db 41h
      db 41 h
     db 41 h
     db 41 h
     db 0                ;why this "db 0"
x:        push dword [Y]
      call [Z]
    
ok, I understood about the "db 0"... obviously!

I'm stupid Wink


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 May 2011, 13:10
View user's profile Send private message Send e-mail Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 241
Mike Gonta 11 May 2011, 21:50
ouadji wrote:
Code:
invoke  Z, [Y], 'AAAA'

Fasm does compile, result :

 call x
      db 41h
      db 41 h
     db 41 h
     db 41 h
     db 0                ;why this "db 0"
x:        push dword [Y]
      call [Z]
    
where this "call" comes from ?
I don't see anything in the macro "invoke" ?

It's part of the pushd macro in the WIN inc files.
Code:
macro pushd value 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;{ match first=,more, value \{ \local ..continue        ;;;; 
;;;;   call ..continue                                     ;;;;
{ match first=,more, value \{ \local ..address, ..continue ;;;; 
   push ..address                                          ;;;;
   jmp ..continue                                          ;;;;
   ..address:                                              ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
   db value,0 
   ..continue: 
   pushd equ \} 
  match pushd =addr var,pushd value \{ \local ..opcode,..address 
   virtual at 0 
    label ..address at var 
    mov eax,dword [..address] 
    load ..opcode from 0 
   end virtual 
   if ..opcode = 0A1h 
    push var 
   else
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;;;;    lea edx,[..address]                                ;;;; 
;;;;    push edx                                           ;;;;
   push eax                                                ;;;; 
   lea eax, [..address]                                    ;;;; 
   xchg eax, [esp]                                         ;;;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   end if 
   pushd equ \} 
  match pushd =double [var],pushd value \{ 
   push dword [var+4] 
   push dword [var] 
   pushd equ \} 
  match pushd =double =ptr var,pushd value \{ 
   push dword [var+4] 
   push dword [var] 
   pushd equ \} 
  match pushd =double num,pushd value \{ \local ..high,..low 
   virtual at 0 
    dq num 
    load ..low dword from 0 
    load ..high dword from 4 
   end virtual 
   push ..high 
   push ..low 
   pushd equ \}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;  match pushd,pushd \{ \local ..continue               ;;;;
  match pushd,pushd \{ \local ..address, ..continue        ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    if value eqtype '' 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;    call ..continue                                    ;;;;
    push ..address                                         ;;;; 
    jmp ..continue                                         ;;;; 
..address:                                                 ;;;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    db value,0 
    ..continue: 
   else 
    push value 
   end if 
   pushd equ \} 
  restore pushd }    

I've shown two small improvements.

_________________
Mike Gonta
the-idiom - journey of discovery

https://the-idiom.com


Last edited by Mike Gonta on 11 May 2011, 22:39; edited 1 time in total
Post 11 May 2011, 21:50
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 11 May 2011, 22:23

thank you Mike Gonta for the clarification!
Quote:

On modern hardware the return prediction facility will get out of order if calls are not returned.
I would never have thought of that.
Very interesting comment.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 May 2011, 22:23
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.