C inline assembler & accessing constants

From: M. Maniak (spamtrap_at_crayne.org)
Date: 03/08/05


Date: Tue, 8 Mar 2005 19:23:04 +0000 (UTC)

Hello,

I'm not quite sure if this newsgroup's the right one and if this
question has been asked a thousand times before, so my apologies in
advance if so...

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'").

My environment:
Compiler: gcc 2.95.3
OS: OpenBSD 3.5 (x86, of course)

Here's the code (please don't laugh..;-) )

-----snip-----
#include <stdio.h>

#define LENGTH 8 // to be used for terminating the loop

static int aInt[LENGTH] = { 1000 ,
                              111 ,
                            -1222 ,
                              333 ,
                             -444 ,
                      -2147483426
      // static: default = 0
      // :
} ;

static int iSum ;

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"
    );
-----snip end-----

Thank's for a hint.

Greets
Peter