delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/17/05:29:16

Message-ID: <D1FB30BBA491D1118E6D006097BCAE390B9202@Probe-nt-2a.Probe.co.uk>
From: Shawn Hargreaves <ShawnH AT Probe DOT co DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: !!Absolute value with inline ASM!!
Date: Tue, 17 Feb 1998 10:26:57 -0000
MIME-Version: 1.0

Henri Ossi writes:
> I need to get the absolute value of a registers (bx)
>
> How is this done in asm.
> (in one command, not using cmp)

I don't know of any such method. I think a test followed by conditional
negation is probably the best you can do: that is what gcc produces for
the abs() function.

> Is there a way to turn off the signed flag somehow or something like
> that?

The sign of a number isn't just a separate flag. The Intel architecture
uses 2's compliment arithmetic, where the highest order bit is given a
negative weighting, eg. the bits in a signed byte represent 1, 2, 4,
8, 16, 32, 64, and -128 respectively. There are many advantages to this
format, but the negate operation works as a toggle rather than an on/off
switch so you will need to know the existing sign before you can get an
absolute value.

	Shawn Hargreaves.

- Raw text -


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