flat assembler
Message board for the users of flat assembler.
Index
> Main > link two object files(in diff lang), error on execute |
Author |
|
crc 16 Apr 2005, 17:48
Try this:
Code: format ELF public main section '.text' executable main: extrn hello push message call hello mov eax,1 xor ebx,ebx int 0x80 section '.data' writeable message db "hello world", 0xA, 0 and link them by doing: Code: gcc first.o second.o -o outputfile Just using 'ld' doesn't get the C runtime stuff in place; without that Linux can't properly identify and load the C library. |
|||
16 Apr 2005, 17:48 |
|
othername 16 Apr 2005, 19:09
Works!
But why it must be main insted _start? _________________ Sorry for my bad English |
|||
16 Apr 2005, 19:09 |
|
crc 16 Apr 2005, 22:52
The C runtime header provides _start, which sets up argc/argv among other things. The provided _start then jumps to main, which is the main entry point for the program in a C-based world.
|
|||
16 Apr 2005, 22:52 |
|
Endre 17 Apr 2005, 11:17
Just one more thing: when a function returns it does not destroy the argument space you have created with push on the stack before calling to it. So you have to do it manually:
Code: push message call hello add esp, 4 ; restore the stack - practically pop message but more general ; even in case of multiple arguments mov ebx, eax ; use return value for exit value mov eax, 1 ; exit follows int 0x80 But you can also exploit this behavior: Code: push message call hello ; message on the stack call hello ; message still on the stack add esp, 4 ; restore the stack mov ebx, eax ; use return value for exit value mov eax, 1 ; exit follows int 0x80 |
|||
17 Apr 2005, 11:17 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.