1

I want to use my .asm function inside C code. So I compiled my fun.asm file to fun.o and linked that object file in CodeBlocks. (I assume that linking is working because if I delete .o file then CodeBlocks error changes to "no such file...".) This is how my code looks like:

.asm code:

SECTION .DATA
    hello:     db 'Hello world!',10
    helloLen:  equ $-hello

SECTION .TEXT
    GLOBAL fun
fun:

say_hi:
    mov eax,4            ; write()
    mov ebx,1            ; STDOUT
    mov ecx,hello
    mov edx,helloLen
    int 80h                 ; Interrupt
  ret                        ; Return control

.c code:


int main(int argc, char *argv[])
{
    extern fun();
    fun();

what is the problem with that code? I get an "undefined reference to 'fun'" error

ziyiyituxe
  • 177
  • 1
  • 9
  • Possible duplicate of [calling assembly function from c](https://stackoverflow.com/questions/13901261/calling-assembly-function-from-c) – thatguy Jun 07 '19 at 16:28
  • 1
    Just a stab: name your function `_fun` in your assembly. – WhozCraig Jun 07 '19 at 16:29
  • Shouldn't it be `extern void fun();` ? – Nikos C. Jun 07 '19 at 16:30
  • 2
    What operating system are you using? The assembly code shown is not 100% correct for any OS I am familiar with; it is closest to correct for Linux/x86-32 but the link error strongly suggests you are _not_ using that operating system. – zwol Jun 07 '19 at 18:06

0 Answers0