www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/01/12:44:20

From: GAMMELJL AT SLU DOT EDU
Date: Thu, 01 Jan 1998 11:42:04 -0600 (CST)
Subject: code which won't compile with -O2 switch on
To: djgpp AT delorie DOT com
Message-id: <01IRV0O32FKIBNJ2GS@SLU.EDU>
Organization: SAINT LOUIS UNIVERSITY St. Louis, MO
MIME-version: 1.0

//The following code compiles and runs correctly. However, if one tries
//to compile it with the -O2 optimization switch, an error message
//"cannot reload integer constant operand in 'asm' " appears.  Why?
//(Note: I don't want a work-around.)  

#include <iostream.h>

unsigned int zmax=10;

#define mode4()                                                 \
__asm__ (                                                           \
    "movl $0x1,%%ecx;"                                              \
    "movl %1(,%%ecx,4),%%eax;"                                      \
    "addl %2(,%%ecx,4),%%eax;"                                      \
    "movl %%eax,%0(,%%ecx,4);"                                      \
    "movl $0x0,%%edx;"                                              \
    "adcl $0x0,%%edx;"                                              \
    "L2: incl %%ecx;"                                               \
    "movl %1(,%%ecx,4),%%eax;"                                      \
    "addl %%edx,%%eax;"                                             \
    "movl $0x0,%%edx;"                                              \
    "adcl $0x0,%%edx;"                                              \
    "addl %2(,%%ecx,4),%%eax;"                                      \
    "movl %%eax,%0(,%%ecx,4);"                                      \
    "adcl $0x0,%%edx;"                                             \
    "cmp _zmax,%%ecx;"                                         \
    "jne L2"                                                      \
    : "=m" (z)                                                    \
    : "g" (x), "g" (y)                                                  \
    : "eax", "ecx", "edx", "memory", "cc");


#define mode3()                                                     \
__asm__ (                                                           \
   "movl $0x0, %%ecx;"                                              \
   "L1: incl %%ecx;"                                               \
   "movl %%ecx,_x(,%%ecx,4);"                                       \
   "movl %%ecx,_y(,%%ecx,4);"                                       \
   "cmp $0xA, %%ecx;"                                               \
   "jne L1"                                                         \
   :                                                                \
   :                                                                \
   : "ecx");

unsigned int x[15],y[15],z[15];

int main()                                                         {
  int i;
  mode3();
  for (i=1;i<11;i++) cout<<x[i]<<" ";
  cout<<'\n';
  for (i=1;i<11;i++) cout<<y[i]<<" ";
  cout<<'\n';
  mode4();
  for (i=1;i<11;i++) cout<<z[i]<<" ";
  cout<<'\n';
  return 0;
                                                                   }


- Raw text -


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