Data Stack - PowerPoint PPT Presentation

About This Presentation
Title:

Data Stack

Description:

NIP. Drop N and pop rest of data stack. T is unchanged. N = N2; 0008. TUCK ... NIP ( a b -- b ) Duplicate T into N2 and push. rest of data stack. N2 = T; when tuck ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 25
Provided by: hask
Category:
Tags: data | niptuck | stack

less

Transcript and Presenter's Notes

Title: Data Stack


1
Data Stack
  • Lecture 8.2
  • A VHDL Forth Core for FPGAs Sect. 3

2
FC16 Forth Core
3
Data Stack
4
A 32 x 16 Stack
5
A 32 x 16 Stack Module
6
stack_ctrl32
entity stack_ctrl is port ( clr in
STD_LOGIC clk in STD_LOGIC
push in STD_LOGIC pop in STD_LOGIC
we out STD_LOGIC amsel out STD_LOGIC
wr_addr out STD_LOGIC_VECTOR (4 downto 0)
rd_addr out STD_LOGIC_VECTOR (4 downto
0) full out STD_LOGIC empty
out STD_LOGIC ) end stack_ctrl  
00000
wr_addr
rd_addr
11111
7
stack_ctrl32
  architecture stack_ctrl_arch of stack_ctrl
is signal full_flag, empty_flag
STD_LOGIC begin stk process(clr, clk, push,
pop, full_flag, empty_flag) variable push_addr,
pop_addr STD_LOGIC_VECTOR(4 downto 0) begin
if clr '1' then push_addr "11111"
pop_addr "00000" empty_flag lt
'1' full_flag lt '0' wr_addr lt
"11111" rd_addr lt "00000" full lt
full_flag empty lt empty_flag
8
stack_ctrl32
elsif clk'event and clk '1' then if
push '1' then if pop 0' then if
full_flag '0' then push_addr
push_addr - 1 pop_addr push_addr
1 empty_flag lt '0' if
push_addr "11111 then full_flag lt
'1' push_addr "00000"
end if end if else - write to
top of stack (pop_addr) without pushing --
dont change push_addr and pop_addr end
if
9
stack_ctrl32
elsif pop '1' then if empty_flag
'0' then pop_addr pop_addr 1
if full_flag '0' then
push_addr push_addr 1 end if
full_flag lt '0' if pop_addr
"00000" then empty_flag lt '1'
end if end if end if
wr_addr lt push_addr rd_addr lt pop_addr
end if
10
stack_ctrl
full lt full_flag empty lt empty_flag
if push '1' and full_flag '0' then we
lt '1' else we lt '0' end if
if push '1' and pop 1' then amsel lt
'1' else amsel lt '0' end if
end process stk end stack_ctrl_arch
11
A 32 x 16 Stack Module
12
Data Stack
13
WHYP Data Stack Instructions
DUP ( 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
14
Data Stack Instructions
15
DUP ( n -- n n )
Duplicate T and push data stack. N lt T N2 lt N
when dup gt nload lt '1' dpush lt '1'
16
SWAP ( a b -- b a )
Exchange T and N. T lt N N lt T
when swap gt tload lt '1' nload lt '1'
tsel lt "111"
17
DROP ( a -- )
Drop T and pop data stack. T lt N N lt N2
when drop gt tload lt '1' nload lt '1'
tsel lt "111" nsel lt "01"
dpop lt '1'
18
OVER ( a b -- a b a )
Duplicate N into T and push data stack. T lt N N
lt T N2 lt N
when over gt tload lt '1' nload lt '1'
tsel lt "111" dpush lt '1'
19
ROT ( a b c -- b c a )
Rotate top 3 elements on stack clockwise. T lt
N2 N lt T N2 lt N
when rot gt tload lt '1' nload lt '1'
tsel lt "110" dpush lt '1'
dpop lt '1'
20
-ROT ( a b c -- c a b )
Rotate top 3 elements on stack counter-clockwise.
T lt N N lt N2 N2 lt T
when mrot gt tload lt '1' nload lt
'1' tsel lt "111" nsel lt "01" ssel
lt '1' dpush lt '1' dpop lt '1'
21
NIP ( a b -- b )
Drop N and pop rest of data stack. T is
unchanged. N lt N2
when nip gt nload lt '1'
nsel lt "01" dpop lt '1'
22
TUCK ( a b -- b a b )
Duplicate T into N2 and push rest of data
stack. N2 lt T
when tuck gt ssel lt '1'
dpush lt '1'
23
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 gt dpop lt '1'
24
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 gt tload lt '1'
nload lt '1' tsel lt "111"
dpop lt '1'
Write a Comment
User Comments (0)
About PowerShow.com