Re: C inline assembler & accessing constants
From: Matt (spamtrap_at_crayne.org)
Date: 03/08/05
- Next message: spamtrap_at_crayne.org: "Re: C inline assembler & accessing constants"
- Previous message: Benjamin David Lunt: "Re: Direct I/O to device on PCI card"
- In reply to: M. Maniak: "C inline assembler & accessing constants"
- Next in thread: Matt: "Re: C inline assembler & accessing constants"
- Reply: Matt: "Re: C inline assembler & accessing constants"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 8 Mar 2005 20:23:32 +0000 (UTC)
M. Maniak skrev:
[...]
> Is it possible to access a constant (say #define LENGTH 8)
> in the assembler section of the C source code per "mov ecx,LENGTH"?
>
> I get an error if I try to do so ("undefined reference to `LENGTH'").
What makes you think that a preprocessor declaration will be applied inside
a string?
[...]
> int main()
> {
> __asm
> (
> ".intel_syntax noprefix\n"
>
> "mov EAX,0\n"
> "mov EBX,0\n" // index
> "mov ECX,LENGTH\n" // just to show the error
> "Loop:\n"
> "cmp EBX,':'\n"
> "jae End\n"
> "add EAX,aInt[EBX*4]\n" // int == 4 byte steps in RAM
> "jo Overflow\n"
> "inc EBX\n"
> "jmp Loop\n"
> "Overflow:\n"
> "mov EAX,':'\n"
> "sub EAX,10\n"
> "End:\n"
> "mov [iSum],EAX\n"
>
> ".att_syntax\n"
> );
Add this after your ".att_syntax\n" line:
: : "i" (LENGTH)
Then you should be able to refer to LENGTH as %0 inside the code. Though it
is a little confusing, see the GCC manual for more information:
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_16.html#SEC175
-Matt
- Next message: spamtrap_at_crayne.org: "Re: C inline assembler & accessing constants"
- Previous message: Benjamin David Lunt: "Re: Direct I/O to device on PCI card"
- In reply to: M. Maniak: "C inline assembler & accessing constants"
- Next in thread: Matt: "Re: C inline assembler & accessing constants"
- Reply: Matt: "Re: C inline assembler & accessing constants"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|