Hi Guys,

I have a simple "yes/no" question concerning, what I believe to be, a typing error in the brilliant AOA (beta version: 7/4/01) textbook.

There's this cool piece of code on page 752, under section, "Calculation Rather than Branching", that computes the absolute value of a number without using any jump/conditional-jump instructions. Here's how it appears in the textbook (note the code assumes eax already contains a number for computation:)

//---------------------------------------------------------------------------------------
// Set EDX to $FFFF_FFFF if EAX is negative, $0000_0000 if EAX is
// zero or positive:
cdq();


// If EAX was negative, the following code inverts all the bits in EAX,
// otherwise it has no effect on EAX.
xor( edx, edx);



// If EAX was negative, the following code adds one to EAX, otherwise
// it doesn?t modify EAX?s value.
and( 1, edx ); // EDX = 0 or 1 (1 if EAX was negative).
add( edx, eax );
//---------------------------------------------------------------------------------------

That second instruction: -
xor(edx, edx);

- is supposed to be: -
xor(edx, EAX);

- right?


I'm pretty sure that's what it's meant to be, but your professional view would strengthen mine, so thank you very much, in advance...
Posted on 2004-04-06 07:22:11 by Jaysen

Hi Guys,


That second instruction: -
xor(edx, edx);

- is supposed to be: -
xor(edx, EAX);

- right?


I'm pretty sure that's what it's meant to be, but your professional view would strengthen mine, so thank you very much, in advance...


Yes, it is.
Obviously xor( edx, edx) simply clears the EDX register, it doesn't invert EAX.
Cheers,
Randy Hyde
Posted on 2004-04-07 14:05:42 by rhyde
What an excellent forum; I can get answers from Mr. Hyde himself! Thank you very much Mr. Hyde.
Posted on 2004-04-08 01:06:35 by Jaysen