Download presentation
Presentation is loading. Please wait.
1
Data Stack Instructions Lab 7
3
Data Stack
4
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
5
Hex OpcodeNameFunction 0000NOP No operation 0001DUP Duplicate T and push data stack. N <= T; N2 <= N; 0002SWAP Exchange T and N. T <= N; N <= T; 0003DROP Drop T and pop data stack. T <= N; N <= N2; 0004OVER Duplicate N into T and push data stack. T <= N; N <= T; N2 <= N; 0005ROT 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; 0007NIP Drop N and pop rest of data stack. T is unchanged. N <= N2; 0008TUCK Duplicate T into N2 and push rest of data stack. N2 <= T; 0009ROT_DROP Drop N2 and pop rest of data stack. T and N are unchanged. Equivalent to ROT DROP 000AROT_DROP_SWAP Drop N2 and pop rest of data stack. T and N are exchanged. Equivalent to ROT DROP SWAP Data Stack Instructions
6
when dup => nload <= '1'; dpush <= '1'; Duplicate T and push data stack. N <= T; N2 <= N; DUP( n -- n n )
7
Exchange T and N. T <= N; N <= T; when swap => tload <= '1'; nload <= '1'; tsel <= "111"; SWAP ( a b -- b a )
8
Drop T and pop data stack. T <= N; N <= N2; when drop => tload <= '1'; nload <= '1'; tsel <= "111"; nsel <= "01"; dpop <= '1'; DROP( a -- )
9
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 )
10
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 )
11
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 )
12
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 )
13
Duplicate T into N2 and push rest of data stack. N2 <= T; when tuck => ssel <= '1'; dpush <= '1'; TUCK( a b -- b a b )
14
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';
15
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';
18
addsub.whp Write a program to enter two 16-bit hex numbers from the switches, add the two numbers, subtract the two numbers, and then AND the sum and difference. Display all numbers and results on the 7-segment displays.
19
: MAIN ( -- ) BEGIN waitB4 S@\ get un1HI00xx DUP DIG! 8 LSHIFTxx00 waitB4 S@\ get un1LOxx00 00yy ORxxyy DUP DIG!\ display un1 waitB4 S@\ get un2HIxxyy 00rr DUP DIG! 8 LSHIFTxxyy rr00 waitB4 S@\ get un2LOxxyy rr00 00ss ORxxyy rrss DUP DIG!\ display un2 OVER OVER\ 2DUPxxyy rrss xxyy rrss waitB4 +\ addxxyy rrss wwzz DUP DIG!\ display sum -ROT\ save sumwwzz xxyy rrss waitB4 - \ subtractwwzz mmnn DUP DIG!\ display difference waitB4 AND\ sum AND diffaabb DIG!\ display sum AND diff AGAIN ; addsub.whp
20
wc16.exe WHYP Compiler
21
type rom_array is array (NATURAL range <>) of STD_LOGIC_VECTOR (15 downto 0); constant rom: rom_array := ( JMP, --0 X"0002", --1 JB4HI, --2 X"0002", --3 JB4LO, --4 X"0004", --5 sfetch, --6 dup, --7 digstore, --8 LIT, --9 X"0008", --a lshift, --b JB4HI, --c X"000c", --d JB4LO, --e X"000e", --f sfetch, --10 orr, --11 dup, --12 digstore, --13 addsub.rom Copy and paste into your Prom.vhd program
22
JB4HI, --14 X"0014", --15 JB4LO, --16 X"0016", --17 sfetch, --18 dup, --19 digstore, --1a LIT, --1b X"0008", --1c lshift, --1d JB4HI, --1e X"001e", --1f JB4LO, --20 X"0020", --21 sfetch, --22 orr, --23 dup, --24 digstore, --25 over, --26 over, --27 JB4HI, --28 X"0028", --29 JB4LO, --2a X"002a", --2b addsub.rom (cont.)
23
plus, --2c dup, --2d digstore, --2e mrot, --2f JB4HI, --30 X"0030", --31 JB4LO, --32 X"0032", --33 minus, --34 dup, --35 digstore, --36 JB4HI, --37 X"0037", --38 JB4LO, --39 X"0039", --3a andd, --3b digstore, --3c JMP, --3d X"0002", --3e X"0000" --3f ); addsub.rom (cont.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.