Hi,

Im writing a program in Turbo C but i also want to use some assembly functions, for this im using nasm.

This is my assembly code:

BITS 16

GLOBAL _Add4

n_Add4 equ 4

_Add4:
	push bp
	mov bp,sp
	
	mov ax, [bp + n_Add4]
	add ax, 4
	
	mov sp,bp
	pop bp
	ret

And here is my Turbo C code:

extern int Add4(int);

void main() {
	int n;
	n = Add4(77);
}

Im linking this way:

nasm -o asmmodule.obj -f obj asmmodule.asm
tcc -mt -c cmodule.c
tlink cmodule.obj asmmodule.obj

But tlink gives me the following error:

Fixup overflow in module CMODULE.C at _TEXT:000B, target = _ADD4

Anyone knows how to fix this?

Seems to be a common problem, only explained in some usenet news threads.

You don't seem to have any segments declared in your ASM code.

Try putting this just above your assembly function definition:

SEGMENT _TEXT PUBLIC CLASS=CODE USE16 ALIGN=16

In addition, I'd suggest putting the following above your single variable declaration:

SEGMENT data

For a more thorough discussion, search "google groups" (USENET news, really) with the following query:

nasm "Fixup overflow" borland

The thread I'm referring to has the following subject:

Help linking a (trivial) NASM object file (.obj) with Borland C++ 3.0

Nice to know that others are still playing with Borland C for DOS + NASM, just like I do :-))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.