Presentation is loading. Please wait.

Presentation is loading. Please wait.

WHYP Test Files Lab 9. y1 The WC16 WHYP Core Modifications for Multiplication and Division.

Similar presentations


Presentation on theme: "WHYP Test Files Lab 9. y1 The WC16 WHYP Core Modifications for Multiplication and Division."— Presentation transcript:

1 WHYP Test Files Lab 9

2 y1 The WC16 WHYP Core Modifications for Multiplication and Division

3 Used only for DIO2 Board 7 different test programs

4 CodeNameFunction 001Dmpp multiply partial product (used for multiplication) 001Eshldc shift left and decrement conditionally (used for division) Table 1 New Funit Instructions

5 -- Function Unit instructions constant plus: opcode := X"0010"; -- + constant minus: opcode := X"0011"; -- - constant plus1: opcode := X"0012"; constant minus1: opcode := X"0013"; constant invert: opcode := X"0014"; -- INVERT constant andd: opcode := X"0015"; -- AND constant orr: opcode := X"0016"; -- OR constant xorr: opcode := X"0017"; -- XOR constant twotimes: opcode := X"0018"; -- 2* constant u2slash: opcode := X"0019"; -- U2/ constant twoslash: opcode := X"001A"; -- 2/ constant rshift: opcode := X"001B"; -- RSHIFT constant lshift: opcode := X"001C";-- LSHIFT constant mpp: opcode := X"001D";-- mpp constant shldc: opcode := X"001E";-- shldc opcodes.vhd

6 Multiply partial product when mpp => tload <= '1'; nload <= '1'; nsel <= "10"; fcode <= icode(5 downto 0); mpp

7 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 In Funit2

8 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

9 : UM* ( u1 u2 - upL upH ) 0 mpp mpp ROT_DROP ; 16 x 16 = 32 Multiplication

10 Shift left and decrement conditionally when shldc=> tload <= '1'; nload <= '1'; nsel <= "10"; fcode <= icode(5 downto 0); shldc

11 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 ;

12 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;

13 32 / 16 = 16:16 Division : UM/MOD ( unL unH ud -- ur uq ) -ROT shldc shldc ROT_DROP_SWAP ;

14 WHYP Test Files sdigtest.whp-- tests the switches and 7-segment displays hex2asc.whp-- converts hex to ascii minmax.whp-- finds the min and max of two numbers mul.whp-- multiplies two 16-bit numbers div.whp-- divides a 32-bit number by a 16-bit number fact16.whp-- computes the factorial of a number leap.whp-- checks if a year is a leap year

15 SDigtest.whp \ Test of JB4HI, JB4LO, and DIG! : main( -- ) BEGIN waitB4 DIG! AGAIN ;

16 Hex2asc.whp \ Convert hex to ASCII HEX : hex2asc ( n -- asc ) 0F AND \ mask upper nibble DUP 9 > \ if n > 9 IF 37 + \ add $37 ELSE 30 + \ else add $30 THEN ; : main( -- ) BEGIN waitb4 DUP DIG! waitb4 hex2asc DIG! AGAIN ;

17 Minmax.whp \MIN MAX : MIN( n1 n2 -- min ) OVER OVER >\ n1 n2 f IF\ n1 n2 SWAP\ n2 n1 THEN DROP ;\ min : MAX( n1 n2 -- max ) OVER OVER <\ n1 n2 f IF\ n1 n2 NIP\ n2 ELSE DROP\ n1 THEN ; : main( -- ) BEGIN waitB4 DUP DIG! waitB4 DUP DIG! waitB4 OVER OVER MIN DIG! waitB4 MAX DIG! AGAIN ;

18 Mul.whp : UM* ( u1 u2 - upL upH ) 0 mpp mpp ROT_DROP ; : MAIN ( -- ) BEGIN waitB4 get u1HI DUP DIG! 8 LSHIFT waitB4 get u1LO OR DUP DIG! waitB4 get u2HI DUP DIG! 8 LSHIFT waitB4 get u2LO OR DUP DIG! waitB4 UM*\ multiply DIG!\ display upH waitB4 DIG!\ display upL AGAIN ;

19 Div.whp : UM/MOD ( unL unH ud -- ur uq ) -ROT shldc shldc ROT_DROP_SWAP ; : MAIN ( -- ) BEGIN waitB4 get unHHI DUP DIG! 8 LSHIFT waitB4 get unHLO OR DUP DIG! waitB4 get unLHI DUP DIG! 8 LSHIFT waitB4 get unLLO OR DUP DIG! SWAP\ numerator waitB4 get udHI DUP DIG! 8 LSHIFT waitB4 get udLO OR\ denominator DUP DIG! waitB4 UM/MOD\ divide DIG!\ display uq waitB4 DIG!\ display ur AGAIN ;

20 Fact16.whp \ Example of BEGIN...WHILE...REPEAT : UM* ( u1 u2 - upL upH ) 0 mpp mpp ROT_DROP ; : *( n1 n2 -- n3 ) UM* DROP ; : factorial ( n -- n! ) 1 2 ROT \ x i n BEGIN \ x i n OVER OVER <= \ x i n f WHILE \ x i n -ROT TUCK \ n i x i * SWAP \ n x' i 1+ ROT \ x' i' n REPEAT \ x i n DROP DROP ; \ x : main( -- ) BEGIN waitB4 DUP DIG! waitB4 factorial DIG! AGAIN ;

21 Leap.whp \ leap year : UM/MOD ( unumL unumH udenom - urem uquot ) -ROT 16 FOR shldc NEXT ROT_DROP_SWAP ; : U/MOD( n1 n2 -- urem uquot ) >R 0 R> UM/MOD ; : MOD( n1 n2 -- urem ) U/MOD DROP ;

22 Leap.whp (cont.) : ?leap ( year -- flag ) DUP 400 MOD 0= IF DROP TRUE ELSE DUP 100 MOD 0= IF DROP FALSE ELSE 4 MOD 0= IF TRUE ELSE FALSE THEN THEN ; : main( -- ) BEGIN waitB4 DUP DIG! 8 LSHIFT waitB4 OR DUP DIG! waitB4 ?leap DIG! AGAIN ; Note: A year is a leap year if it is divisible by 4, but not by 100, or if it is divisible by 400.


Download ppt "WHYP Test Files Lab 9. y1 The WC16 WHYP Core Modifications for Multiplication and Division."

Similar presentations


Ads by Google