Programming Languages From FORTRAN to WHYP Lecture L





















- Slides: 21

Programming Languages From FORTRAN to WHYP Lecture L 5. 2

A Brief History of Programming Languages http: //www. byte. com/art/9509/sec 7/art 19. htm http: //ei. cs. vt. edu/~wwwbtb/book/chap 1/java_hist. html http: //merd. net/pixel/language-study/diagram. html

The first computer bug!

How would you have a computer evaluate this expression? X = A*B + (C – D)/(E + F) Reverse Polish Notation (RPN) Postfix AB*CD-EF+/+

Forth http: //www. ultratechnology. com/dindex. htm

WHYP • Pronounced “whip” • “Words to Help You Program” • Subroutine-threaded Forth for Embedded Systems – 68 HC 11 (16 -bit) – 68332 (32 -bit) – 68 HC 12 (16 -bit)

WHYP is developed from scratch in the book: Design of Embedded Systems Using 68 HC 12/11 Microcontrollers by Richard E. Haskell Prentice Hall, 2000

FORTH is a programming language that -- • • was invented by Charles Moore in the early 70’s 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

Chuck Moore reading Haskell’s WHYP book

WHYP Colon Definitions : squared ( n -- n**2) DUP * ; : cubed ( n -- n**3) DUP n n squared n n**2 * ; n**3

Branching and Looping in WHYP • • • IF…ELSE…THEN FOR…NEXT BEGIN…AGAIN BEGIN…UNTIL BEGIN…WHILE…REPEAT

IF…ELSE…THEN <cond> IF <true statements> ELSE <false statements> THEN <cond> is either TRUE (-1) or FALSE (0)

WHYP Conditional Words < > = <> <= >= 0< 0> 0= U< U> U<= U>= ( ( ( ( n 1 n 2 -n 1 n 2 -n -- f) u 1 u 2 -u 1 u 2 -- f f f ) ) ) f f ) ) (“less-than”) (“greater-than”) (“equals”) (“not-equals”) (“less-than or equal”) (“greater-than or equal”) (“zero-less”) (“zero-greater”) (“zero-equal”) (“U-less-than”) (“U-greater-than”) (“U-less-than or equal”) (“U-greater-than or equal”)


Do different things depending what is in T : check. T ( n -- ) DUP 1 = IF DO 1 ELSE DUP 2 = IF DO 2 ELSE DUP 3 = IF DO 3 ELSE DO 4 THEN ; n f n n n f n n f n

FOR…NEXT Loop n FOR <WHYP statements> NEXT >R drjne <WHYP statements> Decrement top of return stack and branch back to <WHYP statements> if not equal to zero. Therefore, <WHYP statements> are executed n times.

BEGIN…AGAIN BEGIN <WHYP statements> AGAIN

BEGIN…UNTIL BEGIN <WHYP statements> <flag> UNTIL <flag> is either TRUE or FALSE usually from some WHYP conditional word

: GET. BTN ( -- n ) BEGIN BTN@ 0= UNTIL BEGIN BTN@ n UNTIL BTN@ n CHECKT AGAIN ; f

BEGIN…WHILE…REPEAT BEGIN <words> <flag> WHILE <words> REPEAT

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