210 likes | 409 Views
Multiplication and Division. Lab 9. Multiplication. 1101 x 1011 1101 1101 100111 0000 100111 1101 10001111. 13 x11 13 13 143 = 8Fh. Multiplication. 1101 x 1011 1101 1101 100111 0000 100111 1101 10001111. 1101 0000 1011
E N D
Multiplication 1101 x1011 1101 1101 100111 0000 100111 1101 10001111 13 x11 13 13 143 = 8Fh
Multiplication 1101 x1011 1101 1101 100111 0000 100111 1101 10001111 1101 00001011 01101101 adsh 1101 10011110 adsh 1001111 sh 1101 10001111 adsh
Multiplication UM* ( u1 u2 -- upL upH ) T N N2 mpp (multiply partial product) if N(0) = 1 then adsh else sh end if; : UM* ( u1 u2 -- ud) LIT 0 mpp mpp mpp mpp ROT DROP ; All other signed and unsigned multiplication can be derived from UM*
Modifications for Multiplication and Division y1
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); begin AVector := '0' & a; BVector := '0' & b; CVector := '0' & c; y1_tmp := false; yVector := '0' & false;
mpp (multiply partial product) if N(0) = 1 then adsh else sh end if; 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); T N N2
16 x 16 = 32 Multiplication : UM* ( u1 u2 - upL upH ) 0 mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp ROT_DROP ;
Division 10 1010 13 135 13 05 1101 10000111 1101 00111 0000 01111 1101 00101 0000 0101
Division 8-bit/4-bit = 4:4 1010 numer[8:0] denom[3:0] _10000111 1101 1101 10000111 1101 00111 0000 01111 1101 00101 0000 0101 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:4 T N 1010 sll 100001110 1101 1101 10000111 1101 00111 0000 01111 1101 00101 0000 0101 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;
sub1sll 001111110 1101 sll 011111100 1101 001011010 sub1sll rem quot Division 8-bit/4-bit = 4:4 T N 1010 sll 100001110 1101 1101 10000111 N2 1101 00111 0000 01111 1101 00101 0000 0101
Division N2 N T : UM/MOD ( unumL unumH udenom -- urem uquot ) N2 N T -ROT \ udenom unumL unumH SHLDC SHLDC SHLDC SHLDC \ denom quot rem ROT_DROP_SWAP ; All other signed and unsigned division operations can be derived as WHYP words from UM/MOD
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; y <= yVector(width-1 downto 0); y1 <= y1_tmp; 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; T N sll 100001110 1101 N2
32 / 16 = 16:16 Division : UM/MOD ( unL unH ud -- ur uq ) -ROT shldc shldc shldc shldc shldc shldc shldc shldc shldc shldc shldc shldc shldc shldc shldc shldc ROT_DROP_SWAP ;
Hex Division A C EE BC2F B28 9A F C x E = A8 C x E = A8 + A = B2
Hex Division A C EE BC2F B28 9A F 94C 63 Dividend = BC2F Divisor = EE Quotient = CA Remainder = 63 A x E = 8C A x E = 8C + 8 = 94