Features
What's New
Tutorial
Download
Support
Purchase
 
Step 5 - Absolute difference

There are no IF statements in MMX, but the following algorithm is to be implemented:

if (a > b)
   then c = a – b
   else c = b – a

This algorithm can be coded using saturated subtractions: subtracting a from b and b from a, a zero result and the desired absolute difference are obtained,  but since it is impossible to know which is which, the final result is achieved by ORing them together:

c = (a – b) OR (b – a)

A quick examination of this code reveals that a new temporary variable is required, so a new variable called CopySourceImage1 that holds a copy of SourceImage1 should be added. Copying the variable SourceImage1 into CopySourceImage1 is accomplished with another Move 64 bits instruction that has already been described. 
Let's get to the point: to subtract SourceImage2 from SourceImage1, choose the Arithmetic|Subtraction instruction.

SourceImage2 is selected as the Source operand, then SourceImage1 as the Destination operand. As soon as the Destination operand is declared, both the Variable size and type fields are automatically changed to match those of SourceImage1: this happens only if the size and the type of the variable was previously defined in the Variable window. You can always override the choices made by Quexal, in case you need to typecast the variable. The last step is checking the Saturation box, as a saturated subtraction is to be performed. After clicking on the OK button, the main window should look like the following:

Now you can add the second saturated subtraction, then OR the two differences together and store the final result back into memory. The source list should appear as the following:

Download Quexal

Copyright Stefano Tommesani 2000/03