Mulscale

From EDukeWiki
Revision as of 11:27, 21 April 2012 by Helixhorned (talk | contribs) (fix my example.)
Jump to navigation Jump to search

mulscale <res> <eax> <edx> <ecx>

The formula is
res=(eax*edx)>>ecx

The intermediate value is computed using 64 bits to prevent overflow and the result is 32 bits wide. This is a math function which is implemented in assembler programing language because it makes the calculation faster.

The primary use of this function is in calculations involving scaled integers, that is, integers that have a binary point somewhere by convention. For example, the trigonometric functions Sin and Cos use a scaling of 1:16384, corresponding to a 14 bit shift. So, if you wanted to multiply some length (say, dx) by a cosine value (say, cosang), you could write

 mulscale dx dx cosang 14