1 / 23

Data Stack Instructions

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 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 )

quade
Download Presentation

Data Stack Instructions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Stack Instructions Lab 7

  2. Data Stack

  3. 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

  4. Hex Opcode Name Function Data Stack Instructions 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

  5. DUP ( n -- n n ) Duplicate T and push data stack. N <= T; N2 <= N; when dup => nload <= '1'; dpush <= '1';

  6. SWAP ( a b -- b a ) Exchange T and N. T <= N; N <= T; when swap => tload <= '1'; nload <= '1'; tsel <= "111";

  7. DROP ( a -- ) Drop T and pop data stack. T <= N; N <= N2; when drop => tload <= '1'; nload <= '1'; tsel <= "111"; nsel <= "01"; dpop <= '1';

  8. OVER ( a b -- a b a ) Duplicate N into T and push data stack. T <= N; N <= T; N2 <= N; when over => tload <= '1'; nload <= '1'; tsel <= "111"; dpush <= '1';

  9. ROT ( a b c -- b c a ) 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';

  10. -ROT ( a b c -- c a b ) 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';

  11. NIP ( a b -- b ) Drop N and pop rest of data stack. T is unchanged. N <= N2; when nip => nload <= '1'; nsel <= "01"; dpop <= '1';

  12. TUCK ( a b -- b a b ) Duplicate T into N2 and push rest of data stack. N2 <= T; when tuck => ssel <= '1'; dpush <= '1';

  13. 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';

  14. 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';

  15. 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.

  16. addsub.whp : MAIN ( -- ) BEGIN waitB4 S@ \ get un1HI 00xx DUP DIG! 8 LSHIFT xx00 waitB4 S@ \ get un1LO xx00 00yy OR xxyy DUP DIG! \ display un1 waitB4 S@ \ get un2HI xxyy 00rr DUP DIG! 8 LSHIFT xxyy rr00 waitB4 S@ \ get un2LO xxyy rr00 00ss OR xxyy rrss DUP DIG! \ display un2 OVER OVER \ 2DUP xxyy rrss xxyy rrss waitB4 + \ add xxyy rrss wwzz DUP DIG! \ display sum -ROT \ save sum wwzz xxyy rrss waitB4 - \ subtract wwzz mmnn DUP DIG! \ display difference waitB4 AND \ sum AND diff aabb DIG! \ display sum AND diff AGAIN ;

  17. wc16.exe WHYP Compiler

  18. 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

  19. 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.)

  20. 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.)

More Related