Mulscale

From EDukeWiki
Revision as of 06:27, 4 August 2010 by Helixhorned (talk | contribs) (extended this a bit)
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 cosang 14