11.07.2015 Views

Chapter 54

Chapter 54

Chapter 54

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FDPl :FDPZ:sub edx , edx ;make it a 64-bit dividend, then shift: left 16 bits so that result wil be in EAXrol eax,l6 :put fractional part of dividend in: high word of EAXmov dx.ax ;put whole part of dividend in DXsub ax.ax :clear low word EAX ofmov ebx.dword ptr [bp+Divisorlandebx.ebx:positive divisor?jns FOP2:yesdeccx;mark it's a negative divisornegebx:make divisor positivediv ebx:divideshrebx.1;divisor/2. minus 1 if the divisor isadc ebx.O: evendecebxcmp ebx, edx:set Carry if the remainder is at leastadceax.O : half as large as the divisor, then: use that to round up if necessary;should the result be made negative?:no:yes. negate itandcx.cxjz FDP3negeaxFDP3 :else :!DIV-ROUNDING-ONmov edx.[bp+Dividendlsubeax,eaxshrd eax.edx.16:position so that result ends upsaredx.16 : in EAXidiv dword ptr [bp+Divisor]endif :DIV-ROUNDING-ONshld edx.eax.16:whole part of result in DX:: fractional part is already in AXelse: !USE386:NOTE!!! Non-386 division uses a 32-bit dividend but onlv the umer 16 bits: of the divisor: in other words, only the integer part of the divisor is: used. This is done so that the division can be accomplished with two fast: hardware divides instead of a slow software implementation, and is (in my: opinion) acceptable because division is only used to project points to the: screen (normally. the divisor is a 2 coordinate). so there's no cumulative: error, although there wil be some error in pixel placement (the magnitude: of the error is less the farther away from the Z-0 plane objects are). This: is *not* a general-purpose divide, though: if the divisor is less than 1,: for instance, a divide-by-zero error wil result! For this reason, non-386: projection can't be performed for points closer to the viewpoint than Z-1...sub cx, cxmov ax.word ptr [bp+Dividend+Z]andax.axjns CheckSecondOperandD :nonegaxneg word ptr [bp+Dividend]sbbax.0i nc cxCheckSecondOperandD:mov bx.word ptr [bp+Divisor+Eland bx, bxjnsSaveSignStatusD:figure out signs. so we can use: unsigned divisions:assume both operands positive:first operand negative?:yes. so negate first operand:mark that first;second operand negative?:nooperand is negative3-D Shading 101 1

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

Saved successfully!

Ooh no, something went wrong!