Multiplication and Division Lab 9
Multiplication 13 x = 8Fh 1101 x
Multiplication 1101 x adsh adsh sh adsh
Multiplication UM* ( u1 u2 -- upL upH ) TN N2 mpp (multiply partial product) if N(0) = 1 then adsh else sh end if; : UM* ( u1 u2 -- ud) LIT 0 mpp mpp ROT DROP ; All other signed and unsigned multiplication can be derived from UM*
y1 Modifications for Multiplication and Division
variable AVector: STD_LOGIC_VECTOR (width downto 0); variable BVector: STD_LOGIC_VECTOR (width downto 0); variable CVector: STD_LOGIC_VECTOR (width downto 0); variable yVector: STD_LOGIC_VECTOR (width downto 0); variable y1_tmp: STD_LOGIC_VECTOR (width-1 downto 0); AVector := '0' & a; BVector := '0' & b; CVector := '0' & c; y1_tmp := false; yVector := '0' & false; begin
when "011101" =>-- mpp if b(0) = '1' then yVector := AVector + CVector; else yVector := AVector; end if; y <= yVector(width downto 1); y1 <= yVector(0) & b(width-1 downto 1); mpp (multiply partial product) if N(0) = 1 then adsh else sh end if; TN N2
: UM* ( u1 u2 - upL upH ) 0 mpp mpp ROT_DROP ; 16 x 16 = 32 Multiplication
Division
Division 8-bit/4-bit = 4: _ numer[8:0] denom[3:0] If denom < numer[7:4] then overflow (quotient won’t fit in 4 bits) Let T = numer[8:4] N = numer[3:0] N2 = denom[3:0]
Division 8-bit/4-bit = 4: sll TN N2 for I in 0 to 3 loop sll T & N; if T[8:4] > N2 then T := T - (0 & N2); N(0) := ‘1’; end if; end loop;
Division 8-bit/4-bit = 4: sll TN N sub1sll sll sub1sll rem quot
Division : UM/MOD ( unumL unumH udenom -- urem uquot ) All other signed and unsigned division operations can be derived as WHYP words from UM/MOD TN N2 TN -ROT\ udenom unumL unumH SHLDC SHLDC \ denom quot rem ROT_DROP_SWAP ;
when "011110" =>-- shldc yVector := a & b(width-1); y1_tmp := b(width-2 downto 0) & '0'; if yVector > CVector then yVector := yVector - CVector; y1_tmp(0) := '1'; end if; for I in 0 to 3 loop sll T & N; if T[8:4] > N2 then T := T - (0 & N2); N(0) := ‘1’; end if; end loop; sll TN N2 y <= yVector(width-1 downto 0); y1 <= y1_tmp;
32 / 16 = 16:16 Division : UM/MOD ( unL unH ud -- ur uq ) -ROT shldc shldc ROT_DROP_SWAP ;
Hex Division EE BC2F C C x E = A8 C x E = A8 + A = B2 B28 9AF A
Hex Division EE BC2F C A x E = 8C A x E = 8C + 8 = 94 B28 9AF A 94C 63 Dividend = BC2F Divisor = EE Quotient = CA Remainder = 63