22
WHYP Test Files Lab 9

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

Embed Size (px)

Citation preview

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

WHYP Test Files

Lab 9

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

ReturnStack

RmuxPmux

PCclrclk

pload

pinc

IRclrclkirload

WC16_control

plus1

R

Tin

Rin

R T

P

Pin

M

M P1

R

M

The WC16WHYP Core

clkclr

rpop

rpush

psel rinsel

tsel(2:0)

rload

rdec

rsel

T

icode

E1(15:0)

B(1:4)DataStackclk

clr

dpop

dpush

ssel

nloadnsel

tload

y1(15:0)

T

0 11

1

0

0 2 3Tmux

Funit2

NN2

y(15:0)

y NN2E2E1S

S(1:8)

54 6 7

E2(15:0)

P(15:0)

M(15:0)

clr

clk

T(15:0)

N(15:0)

oe

we

Fcode(5:0)

digload

cs

LCD_RW

LCD_RS

LCD_E

y1

The WC16WHYP Core

Modifications forMultiplication and Division

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

WC16

clkclrT

SB

P

M

mclkbn

ProgramROM

P

M DigDisplay

A(1:4) AtoG(6:0)

cclk

clrdigload

T

BTN4 SW(1:8)

Lab9

digload

LD(1:8)

clkdiv cclkIBUFG

clr clkled

ldg

‘1’

oe

we

cs

LCD_RW

LCD_RS

LCD_E

Used only forDIO2 Board

7 differenttest programs

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

Code Name Function

001D mpp multiply partial product (used for multiplication)

001E shldc shift left and decrement conditionally (used for division)

Table 1 New Funit Instructions

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

-- Function Unit instructions

constant plus: opcode := X"0010"; -- +

constant minus: opcode := X"0011"; -- -

constant plus1: opcode := X"0012"; -- 1+

constant minus1: opcode := X"0013"; -- 1-

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

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

Tregclkclr

Nregclkclr

T1

Tin(15:0)

tload

nload

Nmux

Nin

T(15:0)

Smux

stack32x16

N1 T

N2

clkclr

dpop

dpush

empty

full

d

ssel

0

0

1

1

clkclr

dpop

dpush

ssel

nload

nsel(1:0)

tload

DataStack

y1(15:0)y1

2

N(15:0) N2(15:0)

nsel(1:0)

Multiply partial product

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

mpp

R

Tin

M

tsel(2:0)

E1(15:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

y1(15:0)

T

10 2 3Tmux

Funit2

NN2

y(15:0)

y NN2E2E1S

54 6 7

E2(15:0)

T(15:0)

N(15:0)

Fcode(5:0)

Page 7: WHYP Test Files Lab 9. y1 The WC16 WHYP Core 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

In Funit2

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

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;

T N

N2

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

: UM* ( u1 u2 - upL upH )0mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp ROT_DROP ;

16 x 16 = 32 Multiplication

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

Tregclkclr

Nregclkclr

T1

Tin(15:0)

tload

nload

Nmux

Nin

T(15:0)

Smux

stack32x16

N1 T

N2

clkclr

dpop

dpush

empty

full

d

ssel

0

0

1

1

clkclr

dpop

dpush

ssel

nload

nsel(1:0)

tload

DataStack

y1(15:0)y1

2

N(15:0) N2(15:0)

nsel(1:0)

Shift left and decrement conditionally

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

shldc

R

Tin

M

tsel(2:0)

E1(15:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

y1(15:0)

T

10 2 3Tmux

Funit2

NN2

y(15:0)

y NN2E2E1S

54 6 7

E2(15:0)

T(15:0)

N(15:0)

Fcode(5:0)

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

Division

: UM/MOD ( unumL unumH udenom -- urem uquot )

All other signed and unsigned divisionoperations can be derived as WHYP wordsfrom UM/MOD

TNN2

TN N2

-ROT \ udenom unumL unumHSHLDCSHLDCSHLDCSHLDC \ denom quot remROT_DROP_SWAP ;

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

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;

100001110 1101

sllT N

N2

y <= yVector(width-1 downto 0);

y1 <= y1_tmp;

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

32 / 16 = 16:16 Division

: UM/MOD ( unL unH ud -- ur uq ) -ROT

shldc shldc shldc shldcshldc shldc shldc shldcshldc shldc shldc shldcshldc shldc shldc shldc ROT_DROP_SWAP ;

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

WHYP Test Files sdigtest.whp -- tests the switches and 7-segment displayshex2asc.whp -- converts hex to asciiminmax.whp -- finds the min and max of two numbersmul.whp -- multiplies two 16-bit numbersdiv.whp -- divides a 32-bit number by a 16-bit numberfact16.whp -- computes the factorial of a numberleap.whp -- checks if a year is a leap year 

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

SDigtest.whp

\ Test of JB4HI, JB4LO, S@ and DIG! : main ( -- )

BEGIN waitB4 S@ DIG!AGAIN ;

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

Hex2asc.whp\ Convert hex to ASCIIHEX : 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 S@ DUP DIG! waitb4 hex2asc DIG!AGAIN ;

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

Minmax.whp\ MIN MAX : MIN ( n1 n2 -- min )

OVER OVER > \ n1 n2 fIF \ n1 n2 SWAP \ n2 n1THENDROP ; \ min

 

: MAX ( n1 n2 -- max )OVER OVER < \ n1 n2 f IF \ n1 n2 NIP \ n2ELSE DROP \ n1THEN ;

: main ( -- )BEGIN waitB4 S@ DUP DIG! waitB4 S@ DUP DIG! waitB4 OVER OVER MIN DIG! waitB4 MAX DIG!AGAIN ;

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

Mul.whp: UM* ( u1 u2 - upL upH )

0mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp ROT_DROP ;

 : MAIN ( -- ) BEGIN waitB4 S@ \ get u1HI

DUP DIG!8 LSHIFT waitB4 S@ \ get u1LOORDUP DIG!waitB4 S@ \ get u2HIDUP DIG!8 LSHIFT waitB4 S@ \ get u2LOORDUP DIG!waitB4 UM* \ multiplyDIG! \ display upHwaitB4 DIG! \ display upL

AGAIN ;

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

Div.whp: UM/MOD ( unL unH ud -- ur uq ) -ROT

shldc shldc shldc shldcshldc shldc shldc shldcshldc shldc shldc shldcshldc shldc shldc shldc ROT_DROP_SWAP ;

 : MAIN ( -- ) BEGIN waitB4 S@ \ get unHHI

DUP DIG!8 LSHIFTwaitB4 S@ \ get unHLOORDUP DIG!waitB4 S@ \ get unLHIDUP DIG!8 LSHIFT

waitB4 S@ \ get unLLOORDUP DIG!SWAP \ numeratorwaitB4 S@ \ get udHIDUP DIG!8 LSHIFTwaitB4 S@ \ get udLOOR \ denominatorDUP DIG!waitB4 UM/MOD \ divideDIG! \ display uqwaitB4 DIG! \ display ur

AGAIN ;

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

Fact16.whp\ Example of BEGIN...WHILE...REPEAT : UM* ( u1 u2 - upL upH )

0mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp mpp 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 S@ DUP DIG! waitB4 factorial DIG!AGAIN ;

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

Leap.whp\ leap year : UM/MOD ( unumL unumH udenom - urem uquot ) -ROT

16 FOR shldcNEXT

ROT_DROP_SWAP ; : U/MOD ( n1 n2 -- urem uquot )

>R 0 R>UM/MOD ;

 : MOD ( n1 n2 -- urem )

U/MOD DROP ;

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

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 THEN ; : main ( -- )

BEGIN waitB4 S@ DUP DIG! 8 LSHIFT waitB4 S@ OR DUP DIG! waitB4 ?leap DIG!AGAIN ;

Note: A year is a leap yearif it is divisible by 4, butnot by 100, or if it isdivisible by 400.