problems porting ms inline assembly codes to linux (gnu - AT&T syntax) 
Author Message
 problems porting ms inline assembly codes 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  
 problems porting ms inline assembly codes to linux (gnu - AT&T syntax)


Quote:
> 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://asmjournal.freeservers.com/apj_2.txt, 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:

<Jack>

The C language does not define inline assembly language.  Any
implementation is totally non-standard, and this is not the place to
discuss it.  You need to ask in one of the Linux programming groups,

different assemblers for Intel processors are topical.

</Jack>
--
Do not email me with questions about programming.
Post them to the appropriate newsgroup.
Followups to my posts are welcome.



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

 Relevant Pages 

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

2. C libraries, inline assembly and other advanced C on Linux+i386

3. g++, linux, inline assembly question

4. Linux GNU code to Windows code

5. Inline Assembly Code

6. Inline Assembly code in Visual C++

7. Labels for JMP in BC 3.1 inline assembly code

8. Signal Handling Problem for GNU C on Linux

9. Problem with Linux GNU libraries

10. Problem: Inline Assembly Macro

11. Problem with inline assembly for x86 under win ce 4.1

12. ARM Stack switching/Inline assembly problem

 

 
Powered by phpBB® Forum Software