flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > overloading EXTRN

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
I'm using FASM to build modules which are linked together for final EXE. Although the linker can remove EXTRN references that are not used, the OBJ files can get quite large if we include the whole Windows API.

By overloading the EXTRN directive OBJ file size can be kept small.
Code:
; overload extrn to reduce size of obj
macro extrn s {
  match str =as nm:=dword,s \{
    if used nm
      extrn str as nm:dword
    end if
  \}
}    
Using a MAKE utility ensures OBJ files are only updated when changes are made to dependant source code files.

MATCH is quite powerful! Cool
Post 24 Oct 2007, 14:39
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
yep... and multi-pass assembling (which allows "used") is powerfull too.

You might read mine article about external dependencies
Post 24 Oct 2007, 15:29
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
It seems like you were just making note of a deficiency in NASM that caused difficulty in your unified approach.

I like the way FASM allow the interface names to be independant of the source code:
Code:
public YouAreHere as '_Impressive'

YouAreHere:    
Code:
extrn '_Impressive' as NotThereYet:dword

call NotThereYet    
These two files share an interface, by a common name; and yet internally they can use any name. This kind of flexiblity provides (the possiblity of) very good encapsulization of the namespace.
Post 24 Oct 2007, 16:25
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
It seems like you were just making note of a deficiency in NASM that caused difficulty in your unified approach.

kinda... also deficiency of GAS, and also i demonstrated how are things done in FASM and MASM.

by the way, why do you place that ":DWORD" everywhere?
Post 24 Oct 2007, 16:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
vid wrote:
by the way, why do you place that ":DWORD" everywhere?
By that statement I assume it is the default. I have never liked data size defaults - more so on an interface. I doubt Tomasz would change the default and most all will be DWORDS; but I do have some :BYTEs. Should maybe change the macro:
Code:
; overload extrn to reduce size of obj
macro extrn s {
  match str =as nm:d,s \{
    if used nm
      extrn str as nm:d
    end if
  \}
}    
I tried GAS once - maybe 20 years ago - think it was called just AS back then.
Post 24 Oct 2007, 17:24
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
By that statement I assume it is the default. I have never liked data size defaults - more so on an interface. I doubt Tomasz would change the default and most all will be DWORDS; but I do have some :BYTEs. Should maybe change the macro:

no, it isn't default. Default is label without any assigned size.

Difference is demonstrated here:
Code:
label1 dd 10 ;dword size assigned
label2:   ;no size assigned
    dd 10
cmp [label1], 10  ;we know label1 is dword, so this compares dword
mov [label1], eax ;OK, moves to dword at label1
mov [label1], ax  ;error, ax is word and label1 is dword, use following
mov word [label1], ax ;OK
cmp [label2], 10  ;label2 has no size assigned, this throws error
mov [label2], eax ;OK, both eax and label2 are dwords
mov [label2], ax  ;OK, moves to word at label2
    


now i hope you see what is difference between label without any size assigned, and label that has assigned size


Last edited by vid on 24 Oct 2007, 18:53; edited 1 time in total
Post 24 Oct 2007, 18:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
vid, check your example in fasm to see if all comments are true Wink
Post 24 Oct 2007, 18:14
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
vid wrote:
Default is label without any assigned size.
This is good news.

I'll keep assigning a size on the interface when known.

This does bring up and interesting question though: Is the windows API call DWORD or QWORD in Win64? From the PE64DEMO with FASM it does appear that they are QWORDs! I'll need to factor this into my include files it seems.

Thanks for bringing this to light.
Post 24 Oct 2007, 18:31
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
        mov     ecx,eax
        call    [ExitProcess]     
Code:
  kernel_table:
    ExitProcess dq RVA _ExitProcess
    dq 0
    


The type is specified in the label and hence fasm assembles "call qword [ExitProcess]"
Post 24 Oct 2007, 18:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
LocoDelAssembly wrote:
vid, check your example in fasm to see if all comments are true Wink

hell Evil or Very Mad

fixed...
Post 24 Oct 2007, 18:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.