flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > Can Fasm make .o ELF object files?[solved, thanks]

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 174
Can Fasm make .o ELF object files?[solved, thanks]
I need to make a small object file in assembly, so that I can link it with the rest of my C program. Can Fasm do that?

I actually need that for windows program, for mingw compiler, but it uses ELF format for object files.


Last edited by vivik on 03 Aug 2017, 19:22; edited 1 time in total
Post 03 Aug 2017, 16:10
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6602
Location: Kraków, Poland
The ELF object examples are included in the "fasm for Linux" package, so you may have missed them because you work on Windows. They look like:

Code:
; MSGDEMO.ASM
; fasm demonstration of assembling object files

; compile the program using commands like:
;   fasm msgdemo.asm msgdemo.o
;   fasm writemsg.asm writemsg.o
;   ld msgdemo.o writemsg.o -o msgdemo

format ELF

section '.text' executable

 public _start
 _start:

 extrn writemsg

        mov     esi,msg
        call    writemsg

        mov     eax,1
        xor     ebx,ebx
        int     0x80

section '.data' writeable

 msg db "Elves are coming!",0xA,0


Code:
; WRITEMSG.ASM

format ELF

section '.text' executable

 public writemsg

 writemsg:
        mov     ecx,esi
    find_end:
        lodsb
        or      al,al
        jnz     find_end
        mov     edx,esi
        sub     edx,ecx
        mov     eax,4
        mov     ebx,1
        int     0x80
        ret

Post 03 Aug 2017, 19:04
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 667
As already stated by TG, you can compile ELF64 in Windows and produce the desired .o object file, exporting via public keywords. However, if you want to make it workable in windows, you should not use any of the Linux-specific services.


Code:
format ELF64 ;just compile it normally

public business
business:

     ;the non linux-specific code
     
     ret



That's it. You can then use them as GCC's extern in mingw via linking.


Code:
#include <stdio.h>

extern void business(void);

int main()
{
    business();
    return 0;
}



Linking (I used TDM-GCC-64 btw)

Code:
gcc -m64 yourcode.c business.o -o yourcode.exe

Post 03 Aug 2017, 19:19
View user's profile Send private message 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.