WHYP A Programming Language for the FC16 Forth Core.

  • Published on
    21-Dec-2015

  • View
    215

  • Download
    4

Transcript

Slide 1 WHYP A Programming Language for the FC16 Forth Core Slide 2 WHYP Pronounced whip Words to Help You Program Subroutine-threaded Forth for Embedded Systems 68HC11 (16-bit) 68332 (32-bit) 68HC12 (16-bit) Slide 3 WHYP is developed from scratch in the new book: Design of Embedded Systems Using 68HC12/11 Microcontrollers by Richard E. Haskell Prentice Hall, 2000 Slide 4 FORTH is a programming language that --- was invented by Charles Moore in the early 70s is extensible keeps all definitions in a dictionary is extremely compact is recursive can be programmed in RAM, PROM, or ROM is structured uses a stack and postfix notation Slide 5 Chuck Moore reading Haskells WHYP book Slide 6 is extremely modular is interactive is easy to debug allow easy machine access is fast is transportable can be understood in its entirety is unlike any other language FORTH is a programming languages that --- Slide 7 Everything in WHYP is a word WHYP words must be separated by a space WHYP words are stored in a dictionary WHYP words may be either interpreted or compiled When in the interpret mode, a WHYP word is executed When in the compile mode, a WHYP word is stored in the dictionary Introducing WHYP (Forth) Slide 8 If you type a WHYP word and press, the word will be executed (interpret mode) If you type a number (e.g. 6) and press, the number will be pushed on the data stack. WHYP uses the stack to pass parameters from one word to the next. You can define new words in WHYP by stringing together previously defined words. Introducing WHYP (Forth) Slide 9 The Structure of WHYP Serial Line send address PC Target 68HC12 Kernel: LOOP BSR INWDY JSR 0,Y BRA LOOP F82C F82C ----- ----- RTS Dictionary: --- display F82C --- C++ Program Screen C:\>whyp ok display Slide 10 WHYP Arithmetic Operators 7 9 +. 8 5 -. 4 7 *. 8 3 /. 8 3 /MOD.. Slide 11 WHYP Colon Definitions : squared( n -- n**2) DUP * ; : cubed( n -- n**3) DUP\ n n squared \ n n**2 * ;\ n**3 Slide 12 WHYP Stack Manipulation Words DUP( n -- n n ) SWAP( a b -- b a ) DROP( a -- ) OVER( a b -- a b a ) TUCK( a b -- b a b ) ROT( a b c -- b c a ) -ROT( a b c -- c a b ) NIP( a b -- b ) 2DUP( a b -- a b a b ) 2SWAP( a b c d -- c d a b ) 2DROP( a b -- ) 2OVER ( a b c d -- a b c d a b ) Slide 13 WHYP on the FC16 Slide 14 Stack Manipulation Words FC16 Primitives : DUP ( w -- w w ) DUP (0001); : DROP( w -- ) DROP (0003) ; : SWAP ( a b -- b a) SWAP (0002) : NIP ( a b -- b ) NIP (0007); Slide 15 Stack Manipulation Words FC16 Primitives : ROT( a b c -- b c a) ROT (0005) ; : -ROT( a b c -- c a b) MROT (0006) ; : OVER( a b -- a b a) OVER (0004) ; : TUCK ( a b -- b a b) TUCK (0008) Slide 16 Stack Manipulation Words Colon Definitions : 2DUP( a b -- a b a b ) OVER(0004)\ a b a OVER(0004) ;\ a b a b Slide 17 Memory Access Words Fetch \ Fetch word at address T in RAM and \ load it into T : @( a -- w ) fetch (0034) ; Store \ Store the word in N at the address T. \ Pop both T and N. : !( w a -- ) store (010E) ; Slide 18 RAM Module Slide 19 Return Stack Words To-R : >R( w -- ) \ pop T & push to R TOR (0030) ; R-From : R>( -- w ) \ pop R & push to T RFROM (0031) ; R-Fetch : R@( -- w ) \ copy R & push to T RFETCH (0032) ; R-From-Drop : R>DROP( -- ) \ pop R & drop it RFROMDROP (0033) ; Slide 20 Arithmetic Words Plusw3 = w1 + w2 : +( w1 w2 -- w3 ) PLUS (0010) ; minus w3 = w1 - w2 : -( w1 w2 -- w3 ) MINUS (0011) ; Slide 21 Arithmetic Words One-plusw2 = w1 + 1 : 1+( w1 w2 ) PLUS1 (0012) ; One-minus w2 = w1 - 1 : 1-( w1 w2 ) MINUS1 (0013) ; Slide 22 Logical Words Bitwise AND : AND( w1 w2 -- w3 ) ANDD (0015) ; Bitwise OR : OR( w1 w2 -- w3 ) ORR (0016) ; Bitwise XOR : XOR( w1 w2 -- w3 ) XORR (0017) ; Ones complement : INVERT ( w1 -- w2 ) INVERT (0014) ; Slide 23 TRUE = XFFFF : TRUE(-- w ) ONES (0020) ; Logical Words FALSE = X0000 : FALSE(-- w ) ZEROS (0021) ; Slide 24 Branching and Looping in WHYP IFELSETHEN FORNEXT BEGINAGAIN BEGINUNTIL BEGINWHILEREPEAT Slide 25 IFELSETHEN IF ELSE THEN is either TRUE (-1) or FALSE (0) Slide 26 WHYP Conditional Words ( n1 n2 -- f )(greater-than) =( n1 n2 -- f )(equals) ( n1 n2 -- f )(not-equals) =( n1 n2 -- f )(greater-than or equal) 0( n -- f)(zero-greater) 0=( n -- f)(zero-equal) U( u1 u2 -- f )(U-greater-than) U=( u1 u2 -- f )(U-greater-than or equal) Slide 27 Slide 28 >R Decrement top of return stack and branch back to if not equal to zero. Therefore, are executed n times. FORNEXT Loop n FOR NEXT drjne Slide 29 BEGINAGAIN BEGIN AGAIN Slide 30 BEGINUNTIL BEGIN UNTIL is either TRUE or FALSE usually from some WHYP conditional word Slide 31 BEGINWHILEREPEAT BEGIN WHILE REPEAT Slide 32 x = 1; i = 2; WHILE (i Zero-equals -- true if T = 0 (NOT) : 0=( n -- f ) zeroequal (0022) ; FC16 Relational Operator Words Zero-less-than -- true if T < 0 : 0 0 : 0>( n -- f ) DUP 0=\ n f1 SWAP 0< \ f1 f2 OR NOT ; Slide 34 U-less-than -- true if u1 < u2 : U T then ones; else zeros; endif; when ugt Implement these instructions directly In Funit U-greater-than -- true if u1 > u2 : U>( u1 u2 -- f ) ugt (0024); Slide 35 U-greater-than-or equal -- true if u1 >= u2 : U>=( u1 u2 -- f ) ugte (0027) ; Relational Operator Words not-equal-to -- true if n1 /= n2 : ( n1 n2 -- f ) neq (0029) ; U-less-than-or equal -- true if u1 greater-than -- true if n1 > n2 : >( n1 n2 -- f ) gt (002A) ; Relational Operator Words less-than -- true if n1 < n2 : bvs) then y if (avs > bvs) then y if (avs > bvs) then y if (avs > bvs) then y when 101010" => if (avs > bvs) then y = n2 : >=( n1 n2 -- f ) gte (002C) ; Relational Operator Words less-than-or-equal -- true if n1 = n2 : >=( n1 n2 -- f ) gte (002C) ; Relational Operator Words less-than-or-equal -- true if n1 = n2 : >=( n1 n2 -- f ) gte (002C) ; Relational Operator Words less-than-or-equal -- true if n1 =( n1 n2 -- f ) gte (002C) ; Relational Operator Words less-than-or-equal -- true if n1 R --- next DRJNE --- Looping Words"> for (cnt -- )>R --- next DRJNE --- Looping Words

Recommended

View more >