c and assembler program, help me please!

R

Ruben.Colina

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. :)
 
J

Jack Klein

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:


or the moderated group:
 
N

nbaker2328

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/[email protected]/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:


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.
 
R

Ruben.Colina

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://m.../asm/http://www.advancedlinuxprogramming.com/









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
 
A

Andy

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.
 
C

CBFalconer

.... 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
 
C

Chris Thomasson

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?
 
C

Chris Thomasson

Chris Thomasson said:
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.
 
F

Flash Gordon

Chris Thomasson wrote, On 23/02/07 08:07:
Chris Thomasson said:
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.
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top