Assembly with C/C++
Assembly with C/C++
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
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
-
- Member
- Posts: 190
- Joined: Tue Sep 26, 2006 1:40 pm
- Libera.chat IRC: Nokurn
- Location: Ontario, CA, USA
- Contact:
Yes, please do.
That looks wrong. You shouldn't be extern'ing the C file's name, but individual functions, example:
Code: Select all
[extern C-FILE]
Code: Select all
[extern main]
call main
don't forget the '_' suffix, assuming that is a standard and not just a nasm thing.
Website: https://joscor.com
-
- Member
- Posts: 190
- Joined: Tue Sep 26, 2006 1:40 pm
- Libera.chat IRC: Nokurn
- Location: Ontario, CA, USA
- Contact:
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.
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
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.
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.
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]
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]
Code: Select all
nasm -f elf test.asm -o Bootloader