Page 1 of 1
Assembly with C/C++
Posted: Fri Mar 07, 2008 11:57 am
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
Posted: Fri Mar 07, 2008 12:48 pm
by cyr1x
Post the error message's !
Posted: Fri Mar 07, 2008 1:24 pm
by jzgriffin
Yes, please do.
That looks wrong. You shouldn't be extern'ing the C file's name, but individual functions, example:
Posted: Fri Mar 07, 2008 3:01 pm
by 01000101
don't forget the '_' suffix, assuming that is a standard and not just a nasm thing.
Posted: Fri Mar 07, 2008 3:11 pm
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.
Posted: Fri Mar 07, 2008 3:43 pm
by nekros
I believe you should refine your asm skills, and maybe programming in general since you seem to have problems with EXTERN.
Posted: Fri Mar 07, 2008 4:01 pm
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.
Posted: Fri Mar 07, 2008 4:05 pm
by nekros
I think that was sarcasm, I'm not sure though.
Posted: Sat Mar 08, 2008 1:13 am
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.
Posted: Sat Mar 08, 2008 2:47 am
by jzgriffin
You can either force leading underscores (-fleading-underscore) or disable them entirely (-fno-leading-underscore).
Posted: Sat Mar 08, 2008 3:22 am
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]
Posted: Sat Mar 08, 2008 9:27 am
by JamesM
Code: Select all
nasm -f elf test.asm -o Bootloader