4.3.1 ANSWERSTOEXERCISES 583 015 ENTI N A Multiply (Bulletproof web design)
4.3.1 ANSWERSTOEXERCISES 583 015 ENTI N A Multiply v by d. 016 ENTX 0 A 017 2H STX CARRY AN 018 LDA V,l AN 019 MULD AN (as in exercise 13) 026 JIP 2B AN 027 ENTi M+N A (Now rX = 0.) 028 2H STX CARRY A(M + N) Multiply u by d. 029 LDA U.1 ACM -t N) (as in exercise 13) 037 JlP 2B ACM + W 038 STX U A I 26. (See the algorithm of exercise 16.) 101 D8 LDA D 1 (Remainder will be left in 102 DECA 1 1 locations U+M+l through U+M+N) 103 JAZ DONE 1 Terminate if d = 1. 104 ENNl N A rI1 = j -n -1; j + 1. 105 ENTA 0 A r + 0. 106 IH LDX U+M+N+l,l AN rAX+ rb+u,+,. 107 DIV D AN 108 STA U+M+N+l,l AN 109 SLAX 5 AN r +-(rb + IL,+,) mod d. 110 INC2 1 AN jtj+1. 111 J2N IB AN -Repeat for 1 5 j 2 n. 1 At this point, the division routine is complete; and by the next exercise, register AX is zero. 27. It is du mod dv = d(u mod v). 28. For convenience, let us assume that v has a decimal point at the left, i.e., u = (wo.w~v~. . .)b. After step Nl we have 4 2 v < 1 + l/b: for bfl < v(b + 1) 41 + l/b) < 1 + 1 V--= I Vl + 1 J -n+l (llb)(vl + 1) b and > @l(b+ 1 -v,) vl+l -b w1+1 . The latter quantity takes its smallest value when vi = 1, since it is a convex function and the other extreme value is greater. The formula in step N2 may be written so we see as above that v will never become 2 1 + l/b.