Assembly with C/C++

Programming, for all ages and all languages.
Post Reply
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Assembly with C/C++

Post by Baxos »

Hi guys...
I'm new here, i just started on some simple os but im kinda stuck with it right now.. i read some tutorial of making a assembly boot file and it works great and i have added some key interrupts to it in assembly only.. Now im kinda stuck at getting assembly and C working together
i know that i shall use c files in assembly with something like this
[extern C-FILE]
and then just call void's with call _xxx
but i cant get it to work? Maybe my linking is the problem please help me
Thankes :)
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

Post the error message's ! :x
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

Yes, please do.

Code: Select all

[extern C-FILE] 
That looks wrong. You shouldn't be extern'ing the C file's name, but individual functions, example:

Code: Select all

[extern main]
call main
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

don't forget the '_' suffix, assuming that is a standard and not just a nasm thing.
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

You should only need _ if you're working with formats like COFF, AOUT, etc. It shouldn't be necessary with ELF. If you're using DJGPP without ELF support, for example, you will need _. But if you're using Cygwin with a cross compiler, _ won't be needed. The same goes for pretty much any Linux compilation of GCC/Binutils.
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Post by nekros »

I believe you should refine your asm skills, and maybe programming in general since you seem to have problems with EXTERN.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

nekros wrote:I believe you should refine your asm skills, and maybe programming in general since you seem to have problems with EXTERN.
EXTERN can be tricky!

... wait a minute ...

And guess what it did? It boiled, mother.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Post by nekros »

I think that was sarcasm, I'm not sure though.
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Post by DeletedAccount »

Griffin is correct , you do not need the underscore when working with PE and elf formats . you may use the global directive to use asm from C code

eg
GLOBAL my_func


Also .. I think there is a option in gcc to eliminate underscores , something like -fnoleadingunderscores ... i do not remember exactly ... May be,Solar knows this well.
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

You can either force leading underscores (-fleading-underscore) or disable them entirely (-fno-leading-underscore).
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Post by Baxos »

baxos@debian:~/baxos$ nasm test.asm -o Bootloader
test.asm:110: warning: label alone on a line without a colon might be in error
test.asm:123: warning: label alone on a line without a colon might be in error
test.asm:136: warning: label alone on a line without a colon might be in error
test.asm:147: warning: label alone on a line without a colon might be in error
test.asm:11: error: binary output format does not support external references

the code i have on line 11 is :
call _TEST
and i use [extern _TEST]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Code: Select all

nasm -f elf test.asm -o Bootloader 
Post Reply