From: Paul Kelly (longword at domain esatclear.ie)
Date: Tue 12 Jun 2001 - 12:35:47 IST
James Cooper wrote:
> The compiler converts the C code to assembler and then calls another
> program (as86) to compile the assembler into the ones and zeros.
Nope. as86, part of the dev86 package (formerly bin86) produces only
16-bit code. It's used primarily in kernel & LILO compiles to write
whatever small bit of code is required to get from the 16-bit BIOS boot
environment into a running Linux kernel. gcc uses it's own assembler
which uses a different syntax to the old Intel style we know & love from
8086 days and before.
> You can use inline assembler with the __asm__ { ... } block. Look at the
> kernel source codes for some examples of this. You can't use Tasm/Masm
> because the compiler (gcc in your case) doesn't understand the syntax of
> these languages, even though they do the same thing.
It's just the aforementioned alternate assembly syntax within those
blobs of inline assembly (which normally should be avoided at all costs
in any case).
An alternative approach is to write some small functions entirely in
Intel assembly, kept in a separate file. nasm can assemble that into an
ELF object file to be linked against your C program. One thing to be
aware of: Traditionally when calling asm from C your assembler functions
needed to be prefixed with an _ character (printf becomes _printf in
asm). That is NOT the case when you're using ELF binaries.
> kernel memory of the OS calls. The compilers/assemblers have a table of
> where these procedures are located and inserts the address during
> assembly. So for windows the call to printf() might be:
> call 0x34872347 (or whatever the actual address is)
> and for linux it might be:
> call 0x12347558
No! You can't use numbers! That's Wrong.
If you're using libc functions you can link your program against libc
and call the functions by name after pushing the arguments onto the stack.
call printf
If you want to dispense with libc and go straight to the kernel, Linux
uses a syscall mechanism that might be familiar to those who have done
DOS assembly. Each syscall has an assigned number (check
/usr/include/asm/unistd.h for the numbers). You load the syscall number
into EAX then INT 0x80.
>>d) How do I write to my SoundBlaster PCI 128 card under Linux?
> I'm not too sure on this one.
/dev/dsp - visit http://www.opensound.com for a decent description of
the API.
Paul.
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:10:38 GMT