www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/06/22:45:22

From: "Ng Wei Yang" <wyng AT mimos DOT my>
Newsgroups: comp.os.msdos.djgpp
Subject: problems porting ms inline assembly codes to linux (gnu - AT&T syntax)
Date: Thu, 7 Jan 1999 11:41:58 +0800
Organization: Unconfigured
Lines: 110
Message-ID: <771ai0$9kd$1@news5.jaring.my>
NNTP-Posting-Host: carimas10.mimos.my
X-Newsreader: Microsoft Outlook Express 4.72.2106.4
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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:

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
        .type    initPermute__FPUl,@function
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 :)



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019