delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/17/23:05:08

From: Chris Doty <orz AT wpi DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: attempting inline asm in djgpp
Date: Tue, 17 Mar 1998 22:27:50 -0800
Organization: Worcester Polytechnic Institute
Lines: 32
Message-ID: <350F6966.349@wpi.edu>
NNTP-Posting-Host: orz.res.wpi.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am knew to inline assembly under djgpp and 32-bit x86 assembly in
general.  I attempted to code a jumpless variant of abs() and failed.  I
have been unable to determine why.  Please help.  The code follows:

#define  NoJumpsABS(a) ({\
  int c, d; \
  d = a;    \
  __asm__ ( \
    "movl  %1, %0\n" \  //copy input to output
    "sarl $31, %1\n" \  //propogate highest bit(0 if >= 0, -1 if < 0)
    "xorl  %1, %0\n" \  //not output if signed
    "subl  %1, %0\n" \  //inc output if formerly signed
    : "=r" (c) : "r" (d));\
  c;})

testing this with the lines:

int r=256;
printf ("%d, %d, %d", NoJumpsABS(130), 
	NoJumpsABS(-72) + NoJumpsABS(r-13), r);
exit(0);

produced 130, 72, 256 with -O1 on, but 0, 0, 256 with optimization off. 
When I removed the rest of the program that this was stuck in the middle
of the results with -O1 changed to the correct 130, 315, 256, but the no
optimization results stayed the same.  Hopefully I made a stupid mistake
and someone can point out my error?
I'm using PGCC 2.90.23 with DJGPP 2.01.  The program that I originally
stuck this in also used ALLEGRO 3.0.
Looking at the dissambly of my NoJumpsABS with optimization off I found
that both %0 and %1 had been assigned the same register (eax I think). 
How do I stop this from happening?

- Raw text -


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