Changes

Jump to: navigation, search

Programming:Integer Multiplication

261 bytes added, 17:31, 1 March 2018
/* 16bit * 16bit Unsigned -> 32 bits result */ forgotten label
== Very fast 8bit * 8bit Unsigned with only 1K of tables ==
'''Input:''': B A = ''Multiplier'', C L = Multiplicant''Multiplicand''
'''Output:''': DE = ''Product''
'''CPC Cycles''': 104-112 (108 on average) = 26-28 (27) usec
Now for the actual multiply routine:
'''Input:''' A = ''Multiplier'', L = ''Multiplicand''
 
'''Output:''' DE = ''Product''
<pre>
ld h,umul_tab_lo / #100 ; 2
[[User:Executioner|Executioner]] 06:25, 4 April 2008 (CEST)
== Very fast Fast 8bit * 8bit Unsigned with only 512 bytes of tables ==
'''Input''': A = Multiplier, B = Multiplicant
'''Output''': A:E = Product
'''CPC Cycles''': 136-172 (154 on average) = 2634-28 43 (2738.5) usec
'''Size''': 44 bytes of code and 512 bytes for the tables
Fast 8 bit unsigned multiplication with 16 bit result. It uses formula
<prebr> x*y = ((x+y)/2)^<sup>2 </sup> - ((x-y)/2)^<sup>2</sup>, if x+y is even <br> = ((x+y-1)/2)^<sup>2 </sup> - ((x-y-1)/2)^<sup>2 </sup> + y, if x+y is odd and x>=y</pre>
<pre> cp b
[[User:Litwr|Litwr]] 10:25, 24 October 2015 (CEST)
== 16bit * 16bit Unsigned -> 32 bits result == '''Input:''' BC = ''Multiplier'', DE = ''Multiplicand'' '''Output:''' DE,HL = ''Product''<pre>ld hl,0ld a,16muluw add hl,hl rl e rl d jr nc,muluw_cont add hl,bc jr nc,muluw_cont inc demuluw_cont dec a jr nz,muluw</pre> == 16bit * 16bit Unsigned -> 24 bits result ==
'''Input:''' BC = ''Multiplier'', DE = ''Multiplicand''
36
edits