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 > High Level Languages > [solved] Use C with FASM

Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 34

[solved] Use C with FASM

Hello, i have question. Is it possible to link C code for kernel with fasm, and how ? Is it possible to do flat binary with gcc (no specific format)?

Because i found how to do that, but i don't have any success ...
Post 31 May 2018, 15:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15809
Location: Misner space

You can use the "format elf ..." directive to create a file that can be linked with the standard C linkers.

Code:

; fasm example of using the C library in Unix systems

; compile the source with commands like:
;   fasm libcdemo.asm libcdemo.o
;   gcc libcdemo.o -o libcdemo
;   strip libcdemo

format ELF

include 'ccall.inc'

section '.text' executable

 public main
 extrn printf
 extrn getpid

 main:
        call    getpid
        ccall   printfmsg,eax
        ret

section '.data' writeable

 msg db "Current process ID is %d.",0xA,0

Post 31 May 2018, 15:53
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 34

Is it not possible without elf or any format ?

And how you link your program and specify start address point ?

When i use ld, i have error because i have 64 bits platform...
Post 31 May 2018, 16:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15809
Location: Misner space

For 64 bits I think you need "format ELF64".

You might be able to link other formats (mscoff maybe?), but it depends upon your linker, and it depends upon your C code generating something compatible also.
Post 31 May 2018, 16:50
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 34

I need ELF64 ? But the output is ELF ?
Post 31 May 2018, 19:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15809
Location: Misner space

You will have to ask your linker to make the raw binary after the linking stage.
Post 01 Jun 2018, 02:12
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 34

And how you do that ?
Post 01 Jun 2018, 07:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15809
Location: Misner space

That depends upon your linker program. Are you using ld?

I remember that MASM had a separate program called exe2bin for converting PE files to binary.
Post 01 Jun 2018, 08:05
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 34

It's good boy, i have successfully do it ! Just internet don't have many explicit tutorials...

Thanks !
Post 01 Jun 2018, 09:07
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


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.