undefined symbol in module *.c

V

Victor

hello,

I'm trying to write a C program that calls a function that written in
assembly language(X86), but I keeps getting undefined error. I used
paradigm C++ for linking and compiling.

------------------------------------------------------------
;this is output.asm

name output
..186
..MODEL small, c

assume cs: _TEXT
_TEXT segment public 'CODE'
public _output_word


_output_word proc C NEAR

push ax
push dx
push bp ; saves base pointer
mov bp, sp ; base pointer gets stack pointer
mov dx, [bp+4] ; moves port address to dx
mov ax, [bp+6] ; moves data to ax
out dx, ax
pop bp
pop dx
pop ax
ret

_output_word endp

_TEXT ends
end
---------------------------------------------------------------
//this is ccode.c

#define T2CON 0x1000
#define T2_Mode 0xC001

extern void output_word(int port_address, unsigned short data);

void main(void)
{
while(1)
{
output_word(T2CON, T2_Mode);
}

}
---------------------------------------------------------------------
The error message is as follows:

Info :Linking N:\ese476\C Phase 1\cphase1.rom
Warn : :Old-style user-defined stack - stack options ignored
Error: ccode.c(4): Undefined symbol _output_word in module ccode
Warn : :program has no entry point

both files are compiled and assembled under one project and under .axe
files. both files passed the compiler and assembler, but error when I
tried to link them.
any help will be appreciated!


Thanks


-V-
 
K

Kevin Goodsell

Victor said:
hello,

I'm trying to write a C program that calls a function that written in
assembly language(X86),

C, assembly... What makes you think your question is topical on a group
that discusses C++?

For the record, neither C nor C++ define a standard way of calling a
piece of code written in assembly language. You need to ask on a group
that discusses your particular implementation.

http://www.slack.net/~shiva/welcome.txt
http://www.slack.net/~shiva/offtopic.txt

#define T2CON 0x1000
#define T2_Mode 0xC001

extern void output_word(int port_address, unsigned short data);

void main(void)

In C and C++, main returns int. void is not and never has been an
acceptable return type for main.

-Kevin
 
P

Pete Becker

Victor said:
extern void output_word(int port_address, unsigned short data);

extern "C" void output_word(int port_address, unsigned short data);

That will tell the compiler that output_word should be called as if it
were a C function. That will make it easier to match the name mangling.
 
V

Victor

okay, sorry, it's just when I search for this error, lots of other ppl
were posting on this newsgroup. So , sorry, won't repeat it again.

I tried to include "C" on the declaration, but it gave me declaration
terminated incorrectly.
anyway, sorry, I"m gonna post this in the asm newsgroup.

thanks


-V-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top