11.07.2015 Views

Chapter 54

Chapter 54

Chapter 54

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

mov ax, simu1 bxmov bx.axadd cx.dxPOP axmu1 diadd bx.axadc cx.dxmov ax, simu1 diif MUL-ROUNDING-ONadd ax.8000hadc bx.dxelse :!MUL-ROUNDING-ONadd bx.dxendif ;MUL-ROUNDING-ONadc cx.0mov dx.cxmov ax.bxPOP cxand cx,cxjz Fi xedMul Doneneg dxneg axsbb dx.0FixedMulDone::low word M1 times high word M2:accumulate result in CX:BX;retrieve high word of M1;high word M1 times low word MZ:accumulate result in CX:BX:low word M1 times low word M2;round by adding 2^(-17):don't round;accumulate result in:is the result negative?;no. we're all set;yes. so negate DX:AXCX:BXpoppopdisi:restore C register variablesendif :USE386POP bPret- FixedMul endp: Divides one fixed-point value by another.: C near-callable as:; Fixedpoint FixedDiv(Fixedp0int Dividend, Fixedpoint Divisor);FDparms strucdw 2 dup(?) :return address & pushed BPDividend dd ?Divisor dd ?FDparms endsa1 i gn ALIGNMENTpublic JixedOivJixedDi v proc nearpush bpmov bP SSPif USE386if DIV-ROUNDING-ONsub cx.cx ;assume positive resultmov eax.[bp+Oividendland eax,eax ;positive dividend?jns FOP1 :yesinc cx :mark it's a negative dividendneg eax :make the dividend positive101 0 <strong>Chapter</strong> <strong>54</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!