1

Here's the entire assembly program:

.model small .stack 256 .code start: call printer mov ax, 3 ; store 3 into ax mov ah, 76 ; back to DOS mov al, 0 ; no errors int 21h ; interupt -> DOS end start 

And this is where I define the C function printer

#include <stdio.h> void printer() { printf("Hello!\n"); } 

When compiling the assembly code, I get an error: undefined symbol: printer. In C I would do an #include "file.h", how do I achieve the same result here?

2 Answers 2

5

The problem is not compilation, it's linking. You must link (using ld if on Unix/Linux) your executable including the object file with the assembly code and the object file with the C code.

Or put your assembly code into your C file using an "asm" block.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm using TASM to compile the assembly code, and that's when I get the error. There's a separate executable for linking and I don't even reach that stage.
Yeah, but I do get an object file from TASM, it's just that it refuses to make that object file with an undefined symbol.
3

You should add something like

extern _printer 

on the top of your assembly and use call with this name

call _printer 

Correct name of function depends on naming convention of your C compiler. Compiler may add some characters to the C name of the function.

Correct "extern" keyword depends on your assembler and it could be ".extern" or so.

Edit 1: In Turbo Assembler and for that case with function without parameter, it should be just

extrn printer 

or

extrn printer:NEAR 

I am not familiar with TASM.

4 Comments

Nice lead, but this assembler (TASM) doesn't have extern or .extern as a keyword. So I keep getting Illegal instruction. Any other ideas?
@MorganWilde Have you tried EXTRN? stackoverflow.com/questions/14893969/…
@nrz also according to "Turbo Assembler Version 4.0 Users Guide" so updating the answer.
@j123b567 Thanks for the update, solved the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.