Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b --...

23
Data Stack Instructions Lab 7
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    214
  • download

    1

Transcript of Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b --...

Page 1: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

Data Stack Instructions

Lab 7

Page 2: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

PCclrclk

pload

pinc

IRclrclkirload

WC16B_control

R

Tin

P

M

M

M

The WC16BWHYP Core

tsel(2:0)

T

icode

BTN4DataStackclk

clr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

S(1:8)

54 6 7

P(15:0)

M(15:0)

clr

clk

T(15:0)

Fcode(5:0)

digloadN

B

Page 3: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

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)

Data Stack

Page 4: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

WHYP Data Stack InstructionsDUP ( n -- n n )SWAP ( a b -- b a )DROP ( a -- )OVER ( a b -- a b a )ROT ( a b c -- b c a )-ROT ( a b c -- c a b )NIP ( a b -- b )TUCK ( a b -- b a b )ROT_DROP ( a b c -- b c )ROT_DROP_SWAP ( a b c -- c b )2DUP ( a b -- a b a b )Note: 2DUP = OVER OVER

Page 5: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

Hex Opcode Name Function

0000 NOP No operation

0001 DUP Duplicate T and push data stack.N <= T; N2 <= N;

0002 SWAP Exchange T and N.T <= N; N <= T;

0003 DROP Drop T and pop data stack.T <= N; N <= N2;

0004 OVER Duplicate N into T and push data stack.T <= N; N <= T; N2 <= N;

0005 ROT Rotate top 3 elements on stack clockwise.T <= N2; N <= T; N2 <= N;

0006 -ROT Rotate top 3 elements on stack counter-clockwise.T <= N; N <= N2; N2 <= T;

0007 NIP Drop N and pop rest of data stack. T is unchanged.N <= N2;

0008 TUCK Duplicate T into N2 and push rest of data stack.N2 <= T;

0009 ROT_DROP Drop N2 and pop rest of data stack. T and N are unchanged.Equivalent to ROT DROP

000A ROT_DROP_SWAP Drop N2 and pop rest of data stack. T and N are exchanged.Equivalent to ROT DROP SWAP

Data Stack Instructions

Page 6: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

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)

when dup =>

nload <= '1'; dpush <= '1';

Duplicate T and push data stack.

N <= T; N2 <= N;

DUP ( n -- n n )

Page 7: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

R

Tin

M

tsel(2:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

54 6 7

T(15:0)

Fcode(5:0)

N

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)

Exchange T and N.

T <= N; N <= T;when swap =>

tload <= '1'; nload <= '1';

tsel <= "111";

SWAP ( a b -- b a )

Page 8: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

R

Tin

M

tsel(2:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

54 6 7

T(15:0)

Fcode(5:0)

N

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)

Drop T and pop data stack.

T <= N; N <= N2; when drop =>

tload <= '1'; nload <= '1';

tsel <= "111"; nsel <= "01";

dpop <= '1';

DROP ( a -- )

Page 9: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

R

Tin

M

tsel(2:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

54 6 7

T(15:0)

Fcode(5:0)

N

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)

Duplicate N into T and push data stack.

T <= N; N <= T; N2 <= N;

when over => tload <= '1'; nload <= '1';

tsel <= "111";

dpush <= '1';

OVER ( a b -- a b a )

Page 10: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

R

Tin

M

tsel(2:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

54 6 7

T(15:0)

Fcode(5:0)

N

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)

Rotate top 3 elements on stack clockwise.

T <= N2; N <= T; N2 <= N;

when rot => tload <= '1'; nload <= '1'; tsel <= "110"; dpush <= '1'; dpop <= '1';

ROT ( a b c -- b c a )

Page 11: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

R

Tin

M

tsel(2:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

54 6 7

T(15:0)

Fcode(5:0)

N

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)

Rotate top 3 elements on stack counter-clockwise.

T <= N; N <= N2; N2 <= T; when mrot => tload <= '1'; nload <= '1'; tsel <= "111"; nsel <= "01"; ssel <= '1'; dpush <= '1'; dpop <= '1';

-ROT ( a b c -- c a b )

Page 12: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

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)

Drop N and pop rest of data stack.

T is unchanged.

N <= N2;

when nip => nload <= '1'; nsel <= "01"; dpop <= '1';

NIP ( a b -- b )

Page 13: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

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)

Duplicate T into N2 and push

rest of data stack.

N2 <= T;

when tuck => ssel <= '1'; dpush <= '1';

TUCK( a b -- b a b )

Page 14: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

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)

ROT_DROP ( a b c -- b c )

Drop N2 and pop rest of data stack.

T and N are unchanged.

Equivalent to ROT DROP

when rot_drop =>

dpop <= '1';

Page 15: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

R

Tin

M

tsel(2:0)

DataStackclkclr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

54 6 7

T(15:0)

Fcode(5:0)

N

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)

ROT_DROP_SWAP ( a b c -- c b )Drop N2 and pop rest of data stack. T and N are exchanged.Equivalent to ROT DROP SWAP

when rot_drop_swap => tload <= '1'; nload <= '1'; tsel <= "111"; dpop <= '1';

Page 16: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

PCclrclk

pload

pinc

IRclrclkirload

WC16B_control

R

Tin

P

M

M

M

The WC16BWHYP Core

tsel(2:0)

T

icode

BTN4DataStackclk

clr

dpop

dpush

ssel

nloadnsel

tload

T

10 2 3Tmux

Funit1

N2

y(15:0)

y NN2E2E1S

S(1:8)

54 6 7

P(15:0)

M(15:0)

clr

clk

T(15:0)

Fcode(5:0)

digloadN

B

Page 17: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

WC16B

clkclrT

SB

P

M

mclkbn

ProgramROM

P

M DigDisplay

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

cclk

clrdigload

T

BTN4 SW(1:8)

Lab7

digload

LD(1:8)

clkdiv cclkIBUFG

clr clkled

ldg

‘1’

clk

debounce

Page 18: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

addsub.whp

Write a program to enter two 16-bit hex numbers from the switches, add the two numbers, subtract the twonumbers, and then AND the sum and difference.Display all numbers and results on the 7-segment displays.

Page 19: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

: MAIN ( -- ) BEGIN waitB4 S@ \ get un1HI 00xx

DUP DIG!8 LSHIFT xx00waitB4 S@ \ get un1LO xx00 00yyOR xxyyDUP DIG! \ display un1waitB4 S@ \ get un2HI xxyy 00rrDUP DIG!8 LSHIFT xxyy rr00

waitB4 S@ \ get un2LO xxyy rr00 00ssOR xxyy rrssDUP DIG! \ display un2OVER OVER \ 2DUP xxyy rrss xxyy rrsswaitB4 + \ add xxyy rrss wwzzDUP DIG! \ display sum-ROT \ save sum wwzz xxyy rrsswaitB4 - \ subtract wwzz mmnnDUP DIG! \ display differencewaitB4 AND \ sum AND diff aabbDIG! \ display sum AND diff

AGAIN ;

addsub.whp

Page 20: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

wc16.exe WHYP Compiler

Page 21: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

type rom_array is array (NATURAL range <>) of STD_LOGIC_VECTOR (15 downto 0);

constant rom: rom_array := (JMP, --0X"0002", --1JB4HI, --2X"0002", --3JB4LO, --4X"0004", --5sfetch, --6dup, --7digstore, --8LIT, --9X"0008", --alshift, --bJB4HI, --cX"000c", --dJB4LO, --eX"000e", --fsfetch, --10orr, --11dup, --12digstore, --13

addsub.rom

Copy and paste intoyour Prom.vhd program

Page 22: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

JB4HI, --14X"0014", --15JB4LO, --16X"0016", --17sfetch, --18dup, --19digstore, --1aLIT, --1bX"0008", --1clshift, --1dJB4HI, --1eX"001e", --1fJB4LO, --20X"0020", --21sfetch, --22orr, --23dup, --24digstore, --25over, --26over, --27JB4HI, --28X"0028", --29JB4LO, --2aX"002a", --2b

addsub.rom (cont.)

Page 23: Data Stack Instructions Lab 7. Data Stack WHYP Data Stack Instructions DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) ROT( a.

plus, --2cdup, --2ddigstore, --2emrot, --2fJB4HI, --30X"0030", --31JB4LO, --32X"0032", --33minus, --34dup, --35digstore, --36JB4HI, --37X"0037", --38JB4LO, --39X"0039", --3aandd, --3bdigstore, --3cJMP, --3dX"0002", --3eX"0000" --3f);

addsub.rom (cont.)