problem porting assembly codes from ms inline assembly to linux (gnu - AT&T syntax) 
Author Message
 problem porting assembly codes from ms inline assembly to linux (gnu - AT&T syntax)

hi, i m having a problem porting my ms inline assembly codes to linux
platform (using g++ compiler, gnu AT&T syntax).  i read through the A S S E
M B L Y   P R O G R A M M I N G   J O U R N A L
http://www.*-*-*.com/ , n i make some changes to my
previous ms inline assembly codes like changing "register" to "%register", n
"opcode destination, source" to "opcode source, destination".

however, i m still having a problem here which is to access the local
variables in a function.  Here is part of the ms inline assembly codes:

void initPermute(unsigned long *arg)
{
 unsigned long temparray[arraysize];
 unsigned long *temp = temparray;
 unsigned char *table = tInitPermute;

 _asm
 {
  ;Initializes temp.
  mov ecx, arraysize
  mov esi, temp
  mov eax, 00000000h

 loop_init:
  mov [esi], eax
  add esi, 00000004h
  loop loop_init

  mov ecx, 00000001h
  mov ebx, table
  mov esi, arg
  mov edi, temp

and here is the changed assembly codes to port to linux:

void initPermute(unsigned long *arg)
{
        unsigned long temparray[arraysize];
        unsigned long *temp = temparray;
        unsigned char *table = tInitPermute;

        __asm__
        (
                //Initializes temp.
                "movl arraysize, %ecx \n"
                "movl temp, %esi \n"
                "movl $0, %eax \n"

        "loop_init: \n"
                "movl %eax, (,%esi,) \n"
                "addl $4, %esi \n"
                "loop loop_init \n"

                "movl $1, %ecx \n"
                "movl table, %ebx \n"
                "movl arg, %esi \n"
                "movl temp, %edi \n"

and here is the assembly codes compiled by g++ (g++ -S filename):

.globl initPermute__FPUl

initPermute__FPUl:
.LFB1:
        pushl %ebp
.LCFI0:
        movl %esp,%ebp
.LCFI1:
        subl $16,%esp
.LCFI2:
        leal -8(%ebp),%eax
        movl %eax,-12(%ebp)
        movl $tInitPermute,-16(%ebp)
#APP
        movl arraysize, %ecx
        movl temp, %esi
        movl $0, %eax
        loop_init:
        movl %eax, (,%esi,)
        addl $4, %esi
        loop loop_init
        movl $1, %ecx
        movl table, %ebx
        movl arg, %esi
        movl temp, %edi

and here is the compiled errors:

/tmp/cca035041.o(.text+0x1b): undefined reference to `temp'
/tmp/cca035041.o(.text+0x37): undefined reference to `table'
/tmp/cca035041.o(.text+0x3d): undefined reference to `arg'
/tmp/cca035041.o(.text+0x43): undefined reference to `temp'
collect2: ld returned 1 exit status

as you can see here, arraysize is a global variable and there is no problem
referencing it in the assembly codes, however, i can't find a way to
reference the local variables like temp, table and the parameter passed to
the function, arg, in the assembly codes.  i know i can reference using ebp
n some displacements however the problem is if i change the global
arraysize, the data segment will change automatically when it compiled but
those that i use to reference in my assembly codes using ebp and etc will
not change but fix to what i specify at the first place, so it is not
flexible at all.

could anyone give me some hints of how to access the local variables?

i appreciate the help very much n thabk you in anticipation :)



Mon, 25 Jun 2001 03:00:00 GMT  
 problem porting assembly codes from ms inline assembly to linux (gnu - AT&T syntax)


Quote:
> [Having problems porting assembly code to Linux]

>however, i m still having a problem here which is to access the local
>variables in a function.  Here is part of the ms inline assembly codes:

The first thing is to learn how to use inline assembly.  The hard
way is to read the GCC info pages.  The easy way is to read "Brennan's
Guide to Inline Assembly" (which has disappeared from it's old site,
but I have a copy at "http://sag-www.ssl.berkeley.edu/~korpela/djgpp_asm.html")

Your main problem is you're not actually passing the local variables
to the assembly code.  It requires that you actually understand how
inline assembly works including the constraint codes and local labels...
You may need to split it up into multiple

I can't really solve your enitre problem, because you've deleted most of
it.  Here's how I would write what you posted

Quote:
>void initPermute(unsigned long *arg)
>{
>        unsigned long temparray[arraysize];
>        unsigned long *temp = temparray;
>        unsigned char *table = tInitPermute;

         __asm__
         (      
                 //Initializes temp.
          "0:    movl %2,(%1)\n"      
          "      addl $4,%1\n"
          "      loop 0b\n"           /* loop backward to label 0: */

         : /* no outputs */
         : "c" (arraysize),  /* put arraysize in %ecx  %0                */
           "r" (temp)        /* put temp in any available register %1    */
           "r" (0)           /* put 0 in any available register %2       */
         : "%ecx"            /* clobbered register not explicitly listed */
                             /*  in asm code                             */
         );

         __asm__
         (
           ""  /* Whatever assembly code follows what you've posted */
         : /* no outputs that I know of. */  
         : "r" (1)      /* put 1 in any register %0 */
           "r" (table)  /* put table in any other register %1 */
           "r" (arg)    /* put arg in any other register %2 */
           "r" (temp)   /* put temp in any other register %3 */
         : /* no clobbered registers that I know of. */
         );

Quote:
>could anyone give me some hints of how to access the local variables?

You need to access local variable using contstraint codes like the
above.  An actual description is too long for this post.  For a
description, see Brennan's guide at the URL listed above.

Eric
--
Eric Korpela                        |  An object at rest can never be

<a href="http://sag-www.ssl.berkeley.edu/~korpela">Click for home page.</a>



Mon, 25 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. problems porting ms inline assembly codes to linux (gnu - AT&T syntax)

2. Pentium RDTSC timer (+GNU inline assembly) CPUID crashes

3. inline assembly (gcc) on linux x86

4. How to convert this windows inline assembly to Linux

5. Help with optimizing newbie code (inline assembly under VC++ 6.0)

6. Converting Intel Masm to AT&T Gas, and inline assembly

7. Help with optimizing newbie code (inline assembly under VC++ 6.0)

8. how to inline assembly code to visual c++

9. inline assembly & BC++ compiler optimizations

10. Converting Intel Masm to AT&T Gas, and inline assembly

11. 68000 assembly codes and GNU assembler ...

12. gcc inline assembly problem

 

 
Powered by phpBB® Forum Software