By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

c and assembler program, help me please!

P: n/a
i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
i have three files:
a.c
a.h
espera.asm

each files contains the following:
-------------------------------------------------
//espera.asm
global _espera

_espera:
mov ah, 0x00
int 0x16
ret
--------------------------------------------------
//a.c
#include "ruben.h"
int main(void)
{
espera();
return 0;
}
----------------------------------------------------
//a.h
extern void espera(void);

to compile the .asm with nasm i use:
$ nasm -f aout espera.asm -o espera.o

to compile .c file i use:
$gcc -c a.c

to link the files generated i use:
$ ld -o programa espera.o a.o

and it's return the following error:
>ld: aviso: no se puede encontrar el símbolo de entrada _start; usando por >defecto 0000000008048098
a.o: In function `main':
a.c:(.text+0x12): referencia a `espera' sin definir
what is my error, what am doing bad?, please help me
thanks for all!
note: perdon my english i know that is very bad. :-)

Feb 20 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
The error messages are NOT in Enligsh. But you are, possibly, missing
a library.

On Feb 20, 12:24 pm, "Ruben.Col...@gmail.com" <Ruben.Col...@gmail.com>
wrote:
i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
i have three files:
a.c
a.h
espera.asm

each files contains the following:
-------------------------------------------------
//espera.asm
global _espera

_espera:
mov ah, 0x00
int 0x16
ret
--------------------------------------------------
//a.c
#include "ruben.h"
int main(void)
{
espera();
return 0;}

----------------------------------------------------
//a.h
extern void espera(void);

to compile the .asm with nasm i use:
$ nasm -f aout espera.asm -o espera.o

to compile .c file i use:
$gcc -c a.c

to link the files generated i use:
$ ld -o programa espera.o a.o

and it's return the following error:
ld: aviso: no se puede encontrar el símbolo de entrada _start; usando por >defecto 0000000008048098
a.o: In function `main':
a.c:(.text+0x12): referencia a `espera' sin definir

what is my error, what am doing bad?, please help me
thanks for all!
note: perdon my english i know that is very bad. :-)

Feb 20 '07 #2

P: n/a
On 19 Feb 2007 19:24:11 -0800, "Ru**********@gmail.com"
<Ru**********@gmail.comwrote in comp.lang.c:
i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
[snip]

The C language does not define any way to mix code written in any
other language, including assembly language.

Almost all compilers and platforms have some way of doing this, but it
is very different from one compiler/platform combination to another.

So it is not a language issue, but one of your specific
compiler/platform, and that makes it off-topic here.

Places to ask for help on this question:

news:comp.os.linux.development.apps

or the moderated group:

news:comp.lang.asm.x86

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 20 '07 #3

P: n/a
On Feb 19, 10:24 pm, "Ruben.Col...@gmail.com" <Ruben.Col...@gmail.com>
wrote:
i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
i have three files:
a.c
a.h
espera.asm

each files contains the following:
-------------------------------------------------
//espera.asm
global _espera

_espera:
mov ah, 0x00
int 0x16
ret
This "int 0x16" feels like a DOS-style interrupt. You should use
Linux system calls (through "int 0x80") instead. Some reference
material:

http://asm.sourceforge.net/
http://members.save-net.com/jko%40save-net.com/asm/
http://www.advancedlinuxprogramming.com/
--------------------------------------------------
//a.c
#include "ruben.h"
int main(void)
{
espera();
return 0;}

----------------------------------------------------
//a.h
extern void espera(void);

to compile the .asm with nasm i use:
$ nasm -f aout espera.asm -o espera.o

to compile .c file i use:
$gcc -c a.c

to link the files generated i use:
$ ld -o programa espera.o a.o

and it's return the following error:
ld: aviso: no se puede encontrar el símbolo de entrada _start; usando por >defecto 0000000008048098
a.o: In function `main':
a.c:(.text+0x12): referencia a `espera' sin definir

what is my error, what am doing bad?, please help me
thanks for all!
note: perdon my english i know that is very bad. :-)
Nathan.

Feb 20 '07 #4

P: n/a
On 20 feb, 00:03, nbaker2...@charter.net wrote:
On Feb 19, 10:24 pm, "Ruben.Col...@gmail.com" <Ruben.Col...@gmail.com>
wrote:
i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
i have three files:
a.c
a.h
espera.asm
each files contains the following:
-------------------------------------------------
//espera.asm
global _espera
_espera:
mov ah, 0x00
int 0x16
ret

This "int 0x16" feels like a DOS-style interrupt. You should use
Linux system calls (through "int 0x80") instead. Some reference
material:

http://asm.sourceforge.net/http://me...ogramming.com/
--------------------------------------------------
//a.c
#include "ruben.h"
int main(void)
{
espera();
return 0;}
----------------------------------------------------
//a.h
extern void espera(void);
to compile the .asm with nasm i use:
$ nasm -f aout espera.asm -o espera.o
to compile .c file i use:
$gcc -c a.c
to link the files generated i use:
$ ld -o programa espera.o a.o
and it's return the following error:
>ld: aviso: no se puede encontrar el símbolo de entrada _start; usando por >defecto 0000000008048098
>a.o: In function `main':
>a.c:(.text+0x12): referencia a `espera' sin definir
what is my error, what am doing bad?, please help me
thanks for all!
note: perdon my english i know that is very bad. :-)

Nathan.
thanks nathan!
sorry for this here,
can't i use the bios interrupt? i'm trying to do a a program using the
int 10h, first i try to use inline assembly, so i used:

int main(void)
{
__asm__ __volatile("mov $0x00,%ah;int $0x16");
return 0;
}
it compiles without problem in linux and windows but i can't run the
executable, it show me this error: Segmentation fault in both windows
and linux, for this reason i try to use the code that i wrote in my
last post
Feb 20 '07 #5

P: n/a
On 19 Feb 2007 20:28:53 -0800, "Ru**********@gmail.com"
<Ru**********@gmail.comwrote:
>Nathan.
thanks nathan!
sorry for this here,
can't i use the bios interrupt? i'm trying to do a a program using the
int 10h, first i try to use inline assembly, so i used:

int main(void)
{
__asm__ __volatile("mov $0x00,%ah;int $0x16");
return 0;
}
it compiles without problem in linux and windows but i can't run the
executable, it show me this error: Segmentation fault in both windows
and linux, for this reason i try to use the code that i wrote in my
last post
If you want to execute BIOS interrupts, run the program under an
operating system that runs in real mode like DOS.
Feb 20 '07 #6

P: n/a
"Ru**********@gmail.com" wrote:
>
.... snip ...
>
can't i use the bios interrupt? i'm trying to do a a program using
the int 10h, first i try to use inline assembly, so i used:
What bios interrupt? I see no such beast here. Neither does the C
language.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Feb 20 '07 #7

P: n/a
<Ru**********@gmail.comwrote in message
news:11**********************@t69g2000cwt.googlegr oups.com...
i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
i have three files:
[...]

each files contains the following:
-------------------------------------------------
//espera.asm
global _espera
^^^^^^^^^^^^^^

isin't that a syntax error? Try this instead:

..globl _espera
_espera:
If that doesn't work try:

..globl espera
espera:
I know that Mingw makes you use a leading underscore, and GCC for Linux does
not...

FWIW, here is a full-blown example of how to use x86 ASM with C:

http://appcore.home.comcast.net/

BTW, I would use .globl instead of .global for backward compatibility
issues...
Also, nit-picking here... Why not use XOR AH, AH instead of MOV AH, 0x00?
Feb 23 '07 #8

P: n/a
"Chris Thomasson" <cr*****@comcast.netwrote in message
news:ut******************************@comcast.com. ..
<Ru**********@gmail.comwrote in message
news:11**********************@t69g2000cwt.googlegr oups.com...
>i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
i have three files:
[...]

each files contains the following:
-------------------------------------------------
//espera.asm
global _espera
^^^^^^^^^^^^^^

isin't that a syntax error? Try this instead:
Ahh crap! For some reason I thought you were using GAS.
Feb 23 '07 #9

P: n/a
Chris Thomasson wrote, On 23/02/07 08:07:
"Chris Thomasson" <cr*****@comcast.netwrote in message
news:ut******************************@comcast.com. ..
><Ru**********@gmail.comwrote in message
news:11**********************@t69g2000cwt.googleg roups.com...
>>i'm trying to make a program c which use a function in assembler, can
anybody help me, i'm using linux with gcc-4.1 and nasm 0.98.38:
i have three files:
[...]

each files contains the following:
-------------------------------------------------
//espera.asm
global _espera
^^^^^^^^^^^^^^

isin't that a syntax error? Try this instead:

Ahh crap! For some reason I thought you were using GAS.
Don't worry, whatever C compiler is used it is still a syntax error. If
using something other than a C compiler then it isnot topical here so it
does not matter.
--
Flash Gordon
Yes, I know that gas is an assembler not a C compiler.
Feb 23 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.