Post on 15-Jan-2016
description
Data Stack Instructions
Lab 7
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
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
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
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
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 )
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 )
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 -- )
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 )
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 )
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 )
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 )
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 )
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';
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';
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
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
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.
: 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
wc16.exe WHYP Compiler
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
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.)
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.)