Article View: alt.msdos.programmer
Article #693Re: Programming challenge
From: Jerzy Tarasiuk
Date: Mon, 05 Oct 1992 18:14
Date: Mon, 05 Oct 1992 18:14
13 lines
1137 bytes
1137 bytes
>>>>> On 30 Sep 92 18:00:46 GMT, bright@nazgul.UUCP (Walter Bright) said: Walter> I have heard that there is a "well-known trick" for evaluating Walter> (a > b) ? a : b Walter> in assembler language without using any jump instructions. I haven't Walter> been able to discover what that trick is. Does anyone know? Probably something like: mov r1,a / mov r2,b / sub r2,r1 / cmc sbb r3,r3 / and r3,r2 / add r3,r1 / mov result,r3 The SUB sets CF when a>b, CMC complements the CF, after the SBB if a>b r3 is 0 (and then AND gives 0, ADD gives r1=a), otherwise r3 is 0xFFFF (and then AND gives b-a, ADD gives b). This all for unsigned arithmetic only... Jerzy Tarasiuk
Technical Details
Message-ID:
<JT.92Oct5191410@fizyk1.fuw.edu.pl>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!fuw.edu.pl!cocos!jtReferences:
<939@nazgul.UUCP>Show Full Headers
Complete Article Headers
Newsgroups: alt.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!fuw.edu.pl!cocos!jt From: jt@fuw.edu.pl (Jerzy Tarasiuk) Subject: Re: Programming challenge In-Reply-To: bright@nazgul.UUCP's message of 30 Sep 92 18:00:46 GMT Message-ID: <JT.92Oct5191410@fizyk1.fuw.edu.pl> Sender: news@fuw.edu.pl Nntp-Posting-Host: fizyk1 Organization: Warsaw University Physics Dept. References: <939@nazgul.UUCP> Date: Mon, 5 Oct 1992 18:14:10 GMT Lines: 13