Presentation is loading. Please wait.

Presentation is loading. Please wait.

Other WC16 Instructions Lecture L7.4. OpcodeNameFunctionNumber of Clock Cycles Fetch the byte at address T in RAM and load it into T1 Fetch.

Similar presentations


Presentation on theme: "Other WC16 Instructions Lecture L7.4. OpcodeNameFunctionNumber of Clock Cycles Fetch the byte at address T in RAM and load it into T1 Fetch."— Presentation transcript:

1 Other WC16 Instructions Lecture L7.4

2 OpcodeNameFunctionNumber of Clock Cycles 0034@ Fetch the byte at address T in RAM and load it into T1 0036ROM@ Fetch the byte at address T in ROM and load it into T1 0037S@ Fetch the 8-bit byte from Port S and load it into T1 0038DIO2@ Fetch the 8-bit byte from the DIO2 data bus and load it into T.1 0039DIO2! Store the byte in N at the DIO2 address in T. Pop both T and N3 0100LIT Load inline literal to T and push data stack2 0101JMP Jump to inline address2 0102JZ Jump if all bits in T are ‘0’ and pop T2 0106JB1LO Jump if input pin B1 is LO2 0107JB2LO Jump if input pin B2 is LO2 0108JB3LO Jump if input pin B3 is LO2 0109JB0LO Jump if input pin B0 is LO2 010AJB1HI Jump if input pin B1 is HI2 010BJB2HI Jump if input pin B2 is HI2 010CJB3HI Jump if input pin B3 is HI2 010DJB0HI Jump if input pin B0 is HI2 010ERAMSTORE Store the byte in N at the address in T. Pop both T and N2 Other Instructions

3 when lit => tload <= '1'; nload <= '1'; tsel <= "001"; dpush <= '1'; Load inline literal to T and push data stack. LIT

4 when jb0LO => pload <= not B(0); psel <= '0'; pinc <= B(0); Jump if input pin B0 is LO. JB0LO

5 when jb0HI => pload <= B(0); psel <= '0'; pinc <= not B(0); Jump if input pin B0 is HI JB0HI

6

7 Hex2asc.whp \ Convert hex to ASCII HEX : hex2asc ( n -- asc ) 0F AND \ mask upper nibble DUP 9 > \ if n > 9 IF 37 + \ add $37 ELSE 30 + \ else add $30 THEN ; : main( -- ) BEGIN waitb0 S@ DUP DIG! waitb0 hex2asc DIG! AGAIN ;

8 LIT, --2 X"000f", --3 andd, --4 dup, --5 LIT, --6 X"0009", --7 gt, --8 JZ, --9 X"0010", --a LIT, --b X"0037", --c plus, --d JMP, --e X"0013", --f LIT, --10 X"0030", --11 plus, --12 RET, --13 : hex2asc ( n -- asc ) 0F AND \ mask upper nibble DUP 9 > \ if n > 9 IF 37 + \ add $37 ELSE 30 + \ else add $30 THEN ;

9 when jmp => pload <= '1'; psel <= '0'; pinc <= '0'; Jump to inline address. JMP

10 when jz =>-- pop flag pload <= not z; psel <= '0'; pinc <= z; tload <= '1'; nload <= '1'; tsel <= "111"; nsel <= "01"; dpop <= '1'; Jump if all bits in T are ‘0’ and pop T JZ -- z <= '0' if T = all zeros

11 BEGIN…WHILE…REPEAT BEGIN WHILE REPEAT

12 x = 1 i = 2 DO WHILE i <= n x = x * i i = i + 1 ENDDO factorial = x : factorial ( n -- n! ) 1 2 ROT \ x i n BEGIN \ x i n 2DUP <= \ x i n f WHILE \ x i n -ROT TUCK \ n i x i * SWAP \ n x i 1+ ROT \ x i n REPEAT \ x i n 2DROP ; \ x Factorial

13 Fact16.whp \ Example of BEGIN...WHILE...REPEAT : UM* ( u1 u2 - upL upH ) 0 mpp mpp ROT_DROP ; : *( n1 n2 -- n3 ) UM* DROP ; : factorial ( n -- n! ) 1 2 ROT \ x i n BEGIN \ x i n OVER OVER <= \ x i n f WHILE \ x i n -ROT TUCK \ n i x i * SWAP \ n x' i 1+ ROT \ x' i' n REPEAT \ x i n DROP DROP ; \ x : main( -- ) BEGIN waitB0 S@ DUP DIG! waitB0 factorial DIG! AGAIN ;

14 LIT, --1a X"0001", --1b LIT, --1c X"0002", --1d rot, --1e over, --1f over, --20 lte, --21 JZ, --22 X"002d", --23 mrot, --24 tuck, --25 CALL, --26 X"0016", --27 swap, --28 plus1, --29 rot, --2a JMP, --2b X"001f", --2c drop, --2d drop, --2e RET, --2f : factorial ( n -- n! ) 1 2 ROT BEGIN 2DUP <= WHILE -ROT TUCK * SWAP 1+ ROT REPEAT 2DROP ;


Download ppt "Other WC16 Instructions Lecture L7.4. OpcodeNameFunctionNumber of Clock Cycles Fetch the byte at address T in RAM and load it into T1 Fetch."

Similar presentations


Ads by Google