Click here to Skip to main content
16,017,100 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am using NASM on Windows, and was following a tutorial.

maxofthree.asm:
ASM
    global  _maxofthree
    
    section .text
_maxofthree:
    mov     eax, [esp+4]
    mov     ecx, [esp+8]
    mov     edx, [esp+12]
    cmp     eax, ecx
    cmovl   eax, ecx
    cmp     eax, edx
    cmovl   eax, edx
    ret


C
#include <stdio.h>

int maxofthree(int, int, int);

int main() {
    printf("%d\n", maxofthree(1, -4, -7));
    return 0;
}


Then i type in:
nasm -f win64 maxofthree.asm

And it works, but when I do:
gcc callmaxofthree.c maxofthree.obj -o test.exe


It hits me with the good old undefined reference, like this:
ccsGyLZS.o:callmaxofthree:(.text+0x1e): undefined reference to `maxofthree'
collect2.exe: error: ld returned 1 exit status


What I have tried:

I don't know what to try I want to start with Assembly program but it's not going very well.
Posted
Updated 23-Nov-22 13:39pm

1 solution

your subroutine in asm file is _maxofthree, but your C program is looking for maxofthree, with no leading underscore. You should be able to get a clean link if you change the name of one or the other.
 
Share this answer
 
Comments
CodeSie Programming 23-Nov-22 21:18pm    
Huh, don't know why I didn't try that haha. It said to do it like this in the tutorial so i just followed that, thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900