Hi Victor,

Not being a mathematician, I did not previously know your formula. Thanks for that insight.

WRT your SETA/SETC comment, yes the following sequence would produce |A-B| ...
   &A SETA 3
   &B SETA 8
   &C SETA &A-&B
   &D SETC '&C'
   &E SETA &D
&C's value would be -5.
&E's value would be +5.

However... I did stipulate that the solution I have in mind "does not use macro pass logic at all, no SETx symbols, no nothing."

In particular, I was thinking only of the arithmetic that can be used in EQU statements.

And the particular arithmetic rules quirk that makes it all possible is that division by zero is allowed and results in a value of zero.

BTW, I don't know of any easy way for an EQU statement to compute an absolute value.




FWIW, I remain impressed by Bob Ngan's solution using ORG statements. It can quite beautifully be generalized into a macro call such as:
     RESULT MAX A,B
    +RESULT EQU *-generateddsectname

where the messiness of generating a dsect with a random name, followed by suitable ORGs followed by resumption of the interrupted xSECT via a LOCTR is hidden from view via PRINT OFF/ON statements.


Dave Cole







At 6/18/2015 09:22 AM, Victor Gil wrote:

I am guessing the answer to your MAX question boils down to this

Max(A,B) = (|A-B|+A+B)/2

and probably takes advantage of an Assembler arithmetic rule which produces |A-B|.

Maybe this one:

"If a SETA symbol is used in the operand field of a SETC statement, the arithmetic value is converted to an unsigned integer"

-Victor-


=========================================
I think John has started something here... So here's an interesting
problem I had to solve some years ago...

1) Given two non-relocatable equates, define a third equate that is
equal to the MAX of those two. (As far as I know, the Assembler still
does not offer MAX and MIN built-in functions.)

2) Extend that solution to three or more equates. (One z/XDC macro
has internal logic that resolves the MAX of around fifty equates. It
goes on and on for pages!)

The answer I have in mind works for equates that are not resolvable
at macro pass time. In fact, the solution does not use macro pass
logic at all, no SETx symbols, no nothing.

Hint: Central to the ability to do this is a rather "unusual"
characteristic of the rules of arithmetic that the Assembler follows.
(Did I just give it away?)



Now I'm sure some of you, like me, have worked this out decades ago,
so if you already know how to do this, feel free to brag, but please
hold off posting an actual answer for a few days to give others a
crack at this exercise.

Thanks,
Dave Cole
ColeSoft Marketing
414 Third Street, NE
Charlottesville, VA 22902
EADDRESS:     [email protected]

Home page:    www.colesoft.com
User's Group: www.xdc.com (on LinkedIn)
Facebook:     www.facebook.com/colesoftware
Videos:       www.youtube.com/user/colesoftware

Dave Cole
ColeSoft Marketing
414 Third Street, NE
Charlottesville, VA 22902
EADDRESS:     <mailto:[email protected]>[email protected]

Home page:    www.colesoft.com
User's Group: www.xdc.com (on LinkedIn)
Facebook:     www.facebook.com/colesoftware
Videos: www.youtube.com/user/colesoftware

Reply via email to