CSE 378 Fall 2002 Computer Hardware Design R. E. Haskell Lab 9 – The WC16 Core – Multiplication and Division – DIO2 Board The WC16 Core A final version of the WC16 core is shown in Figure 1. Note that it includes a new Funit, called Funit2, which includes the multiplication and division primitives, mpp and shldc, shown in Table 1. Table 2 is a list of new I/O instructions and Table 3 is a list of additional transfer and multi-cycle instructions. These instructions are included in the package opcodes.vhd used in Labs 7 and 8. The top-level design for Lab 9 is shown in Figure 2. Table 1 New Funit Instructions Code 001D 001E Name mpp shldc Function multiply partial product (used for multiplication) shift left and decrement conditionally (used for division) Table 2 New I/O Instructions Code 0034 003A Name @ DIO2@ Function “Fetch” Push contents of RAM address, T, into T via E1. “DIO2 fetch” Push 8-bit value to DIO2 data bus into T via E1. Table 3 New Transfer and Multi-Cycle Instructions Code 0106 0107 0108 0109 010A 010B 010C 010D 010E 010F 0110 Name JB1LO JB2LO JB3LO JB4LO JB1HI JB2HI JB3HI JB4HI ! DIO2! LCDinst! 0111 LCDdata! Function Jump if input pin B1 is LO Jump if input pin B2 is LO Jump if input pin B3 is LO Jump if input pin B4 is LO Jump if input pin B1 is HI Jump if input pin B1 is HI Jump if input pin B1 is HI Jump if input pin B1 is HI “Store” Write the word in N at the address in T. Pop both T and N. Write the byte in N at the DIO2 address in T. Pop both T and N. Write the instruction byte in N at the DIO2 dummy address (0) in T. Pop both T and N. Write the data byte in N at the DIO2 dummy address (0) in T. Pop both T and N. 1 M R 0 psel P1 T 0 Pmux 1 rinsel Rmux 1 Rin Pin P(15:0) pload pinc clr clk PC plus1 P rsel rload rdec ReturnStack clr clk rpush rpop E1(15:0) S(1:8) R M(15:0) M y M irload 0 1 E2(15:0) S 2 E1 E2 N2 3 4 Tmux clr clk IR 5 6 N 7 tsel(2:0) Tin tload icode R B(1:4) T clr clk nload nsel ssel clr clk dpush dpop DataStack oe we WC16_control N2 cs N T T(15:0) digload N(15:0) LCD_RW Funit2 LCD_RS LCD_E y1(15:0) The WC16 WHYP Core Fig. 1 The WC16 WHYP Core 2 Fcode(5:0) y(15:0) bn mclk IBUFG clkdiv Lab9 clr led P cclk clk clk clr P T T Program ROM clr M DigDisplay M WC16 cclk digload oe we cs LCD_RW LCD_RS LCD_E B S BTN4 SW(1:8) ‘1’ LD(1:8) Fig. 2 Lab 9 Top-level Design 3 ldg A(1:4) AtoG(6:0) digload Multiplication and Division Multiplication of a 16-bit unsigned number in T by a 16-bit unsigned number in N producing a 32-bit product in T:N can be accomplished by adding the variables shown in Figure 3 to the process in Funit2 and by implementing the Funit2 operation mpp as shown in Figure 4. variable variable variable variable variable AVector: BVector: CVector: yVector: y1_tmp: STD_LOGIC_VECTOR STD_LOGIC_VECTOR STD_LOGIC_VECTOR STD_LOGIC_VECTOR STD_LOGIC_VECTOR (width downto 0); (width downto 0); (width downto 0); (width downto 0); (width-1 downto 0); Fig. 3 Variables to add to process in Funit2 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); 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; Fig. 4 Implementation of mpp and shldc in Funit2 The WHYP word UM* ( u1 u2 - upL upH ) can then be implemented using the colon definition shown in Figure 5. Note that this multiplication will take 23 clock cycles to execute, including the CALL and RET instructions (2 clock cycles each). : UM* ( u1 u2 - upL upH ) 0 mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp ROT_DROP ; Fig. 5 The WHYP multiplication word, UM* 4 Dividing a 32-bit unsigned number in N2:N by a 16-bit unsigned number in T producing a 16-bit quotient in T and a 16-bit remainder in N can be accomplished by adding the variables shown in Figure 3 to the process in Funit2 and by implementing the Funit2 operation shldc as shown in Figure 4. The WHYP word UM/MOD ( unL unH ud -- ur uq ) can then be implemented using the colon definition shown in Figure 6. Note that this division will take 22 clock cycles to execute, including the CALL and RET instructions. : 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 ; Fig. 5 The WHYP division word, UM/MOD DIO2 Board The DIO2 board that is connected to the Digilab2 board contains 15 pushbutton switches, 16 LEDs, 8 switches, four 7-segment displays, and a Liquid Crystal Display (LDC). All the I/O devices except the LCD are controlled through a Xilinx CPLD that is on the DIO2 board. The operation of this DIO2 board is described in the DIO2 Reference Manual, available online from www.digilentinc.com. 5 Lab 9 1. Modify the function unit, Funit1, used in Lab 8 to include the new operations, mpp and shldc. Call the new function unit Funit2. Note that this function unit has three input busses and two output busses. 2. Write a structural VHDL program for the module WC16 shown in Figure 1. Write the VHDL program for the controller WC16_control (modify WC16C_control.vhd from Lab 8). In addition to all of the instructions from Lab 8, implement the new instructions in Table 1. 3. Write a structural VHDL program for the top-level design Lab9 shown in Figure 2. 4. Test your Lab9 module by compiling each of the following WHYP programs (available on the web) using the program WC16.EXE (available on the web) that will produce the VHDL code to insert in your ROM program and then download the program to the Spartan II board. Demonstrate each program to your lab instructor as you get it to work. sdigtest.whp hex2asc.whp minmax.whp mul.whp div.whp fact16.whp leap.whp -------- tests the switches and 7-segment displays converts hex to ascii finds the min and max of two numbers multiplies two 16-bit numbers divides a 32-bit number by a 16-bit number computes the factorial of a number checks if a year is a leap year Extra credit: Implement one or more of the instructions in Tables 2 and 3 that relate to the DIO2 board. Run one or more of the .whp programs in Part 4 above where the input and/or output use the DIO2 board. 6
© Copyright 2026 Paperzz