<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
It is interesting to note that NT386 doesn't use the m3_mod/div functions, but generates inline code:<BR>
 <BR>
PROCEDURE diffdivOp (t: T; READONLY divisor: Operand; apos: BOOLEAN) =<BR>  VAR<BR>    diffsignlab := reserve_labels(t, 1, TRUE);<BR>    endlab := reserve_labels(t, 1, TRUE);<BR>  BEGIN<BR>    <* ASSERT divisor.loc = OLoc.register *><BR>    movOp(t, t.reg[EDX], t.reg[EAX]);                 (*   MOV EDX, EAX      *)<BR>    binOp(t, Op.oXOR, t.reg[EDX], divisor);           (*   XOR EDX, divisor  *)<BR>    brOp(t, Cond.L, diffsignlab);                     (*   JL  diffsignlab   *)<BR>    IF apos<BR>      THEN binOp(t, Op.oXOR, t.reg[EDX], t.reg[EDX]); (*   XOR EDX, EDX      *)<BR>      ELSE noargOp(t, Op.oCDQ);                       (*   CDQ               *)<BR>    END;<BR>    idivOp(t, divisor);                               (*   IDIV EAX, divisor *)<BR>    brOp(t, Cond.Always, endlab);                     (*   JMP endlab        *)<BR>    set_label(t, diffsignlab);                        (* .diffsignlab        *)<BR>    noargOp(t, Op.oCDQ);                              (*   CDQ               *)<BR>    idivOp(t, divisor);                               (*   IDIV EAX, divisor *)<BR>    immOp(t, Op.oCMP, t.reg[EDX], TZero);             (*   CMP EDX, #0       *)<BR>    brOp(t, Cond.E, endlab);                          (*   JE  endlab        *)<BR>    decOp(t, t.reg[EAX]);                             (*   DEC EAX           *)<BR>    set_label(t, endlab);                             (* .endlab             *)<BR>  END diffdivOp;<BR>
 <BR>
PROCEDURE diffmodOp (t: T; READONLY divisor: Operand; apos: BOOLEAN) =<BR>  VAR<BR>    diffsignlab := reserve_labels(t, 1, TRUE);<BR>    endlab := reserve_labels(t, 1, TRUE);<BR>  BEGIN<BR>    <* ASSERT divisor.loc = OLoc.register *><BR>
    movOp(t, t.reg[EDX], t.reg[EAX]);                 (*    MOV EDX, EAX      *)<BR>    binOp(t, Op.oXOR, t.reg[EDX], divisor);           (*    XOR EDX, divisor  *)<BR>    brOp(t, Cond.L, diffsignlab);                     (*    JL  diffsignlab   *)<BR>    IF apos<BR>      THEN binOp(t, Op.oXOR, t.reg[EDX], t.reg[EDX]); (*    XOR EDX, EDX      *)<BR>      ELSE noargOp(t, Op.oCDQ);                       (*    CDQ               *)<BR>    END;<BR>    idivOp(t, divisor);                               (*    IDIV EAX, divisor *)<BR>    brOp(t, Cond.Always, endlab);                     (*    JMP endlab        *)<BR>    set_label(t, diffsignlab);                        (* .diffsignlab         *)<BR>    noargOp(t, Op.oCDQ);                              (*    CDQ               *)<BR>    idivOp(t, divisor);                               (*    IDIV EAX, divisor *)<BR>    immOp(t, Op.oCMP, t.reg[EDX], TZero);             (*    CMP EDX, #0       *)<BR>    brOp(t, Cond.E, endlab);                          (*    JE  endlab        *)<BR>    binOp(t, Op.oADD, t.reg[EDX], divisor);           (*    ADD EDX, divisor  *)<BR>    set_label(t, endlab);                             (* .endlab              *)<BR>  END diffmodOp;<BR><BR>
 <BR>
I haven't tested it yet, but of course you can see that same signed inputs are simpler, like with the code in hand.c.<BR>
I'm really starting to like CARDINAL and not INTEGER. :)<BR>
(Plus the subtlety that CARDINAL has a default initialization to 0 that Tony told me about.)<BR>
 <BR>
 <BR>
 - Jay<BR>                                     </body>
</html>