www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/31/00:02:08

To: djgpp AT delorie DOT com
Subject: Re: Inline Asm?
Message-ID: <19961231.204032.5015.0.chambersb@juno.com>
From: chambersb AT juno DOT com (Benjamin D Chambers)
Date: Mon, 30 Dec 1996 23:36:55 EST

Well, I spent some time stepping through my program with GDB, and found
that the following lines caused problems:

cmpl	$0,	%%edx  (This is, of course, in the c file)
jne	0

Now, to me, this means that if edx is not zero, jump to the label 0
(which was defined earlier) and, if edx is zero, keep executing as
normal.  However, when I stepped through this with GDB, I found that no
matter what value edx held, the loop fell through (that is, no jump was
performed).  Am I doing something wrong here?  Again, thanx in advance...

...Chambers
(PS: Here is the original program (a whole 20 lines)):
#include <malloc.h>
#include <stdio.h>

unsigned char *data;
int size;

int main(void)
{
  size=20;
  data=(unsigned char *)malloc(size);
  size=16;
  asm("0:                                       \n
        movb    $1,             (,%%eax,1)      \n
        incl    %%eax                           \n
        decl    %%edx                           \n
        cmpl    $0,             %%edx           \n
        jne     0                               \n
       "
  :     // No Output
  : "d" (size),
    "a" (data)
  : "memory", "%cc"
  );
  for (size=0;size<16;size++)
   printf("At line %d: %d\n",size,data[size]);
  return(0);
}

- Raw text -


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