A Programming Language for the FC16 Forth Core

Slides:



Advertisements
Similar presentations
PbForth + sum ! By Josh Jennings Ratnakar Kamath.
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
7-5 Microoperation An elementary operations performed on data stored in registers or in memory. Transfer Arithmetic Logic: perform bit manipulation on.
Recursion CS 367 – Introduction to Data Structures.
1 Chapter 3 Jump, Loop, and Call Instructions. 2 Sections 3.1 Loop and Jump Instructions 3.2 Call Instructions 3.3 Time Delay Generation and Calculation.
Recursion vs. Iteration The original Lisp language was truly a functional language: –Everything was expressed as functions –No local variables –No iteration.
Computer Organization and Architecture
World’s first Forth compiler for the.NET platform Valer BOCAN, PhD.
Instruction Set Architecture
Instruction Set Architecture & Design
Forth Lecture L7.1. A Brief History of Programming Languages
Data Stack Lecture 8.2 A VHDL Forth Core for FPGAs: Sect. 3.
Return Stack Lecture 8.4 A VHDL Forth Core for FPGAs: Sect. 5.
Programming Languages From FORTRAN to WHYP. A Brief History of Programming Languages
1 Comparators Discussion D A 1-Bit Comparator The variable Gout is 1 if x > y or if x = y and Gin = 1. The variable Eout is 1 if x = y and Gin =
Multi-Base Calculator CSE378 Final Project By Matthew Lehn & Yanqing Zhu December 17, 2001 Professor Haskell.
EECC250 - Shaaban #1 Lec # 5 Winter Stacks A stack is a First In Last Out (FILO) buffer containing a number of data items usually implemented.
Lab 6 Program Counter and Program ROM Mano & Kime Sections 7-1 – 7-6.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell WHYP -- An Extensible Language Chapter 4.
The FC16 Forth Core Lab 7 Module F4.1. Lab 7 Hex OpcodeNameFunction 0000NOP No operation 0001DUP Duplicate T and push data stack. N
Return Stack Lecture L7.3. A 32 x 16 Stack Same as used in the Data Stack in Lab 7.
Logic Design Fundamentals - 2 Lecture L1.2. Logic Design Fundamentals - 2 Basic Gates Basic Combinational Circuits Basic Sequential Circuits.
Programming Example Lecture 8.6 A VHDL Forth Core for FPGAs: Sect. 7.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
8051 ASSEMBLY LANGUAGE PROGRAMMING
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.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell Subroutine and Stacks Chapter 2.
Other WC16 Instructions Lecture L7.4. OpcodeNameFunctionNumber of Clock Cycles Fetch the byte at address T in RAM and load it into T1 Fetch.
1 Comparators: Procedures Discussion D9.2 Example 22.
Microcontroller Intel 8051
VHDL Examples Subra Ganesan Reference: Professor Haskell’s Notes,
Assembly Language Part 5. Reference parameter/global variable model C++ reference parameters are references to the actual arguments (as opposed to copies.
Forth A stack language.
PZ07A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07A - Expressions Programming Language Design and Implementation.
Machine Instruction Characteristics
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
The 8051 Assembly Language Branching & Subroutines
Objective At the conclusion of this chapter you will be able to:
Computer Architecture and Organization
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Today’s Lecture Unconditional branch instruction
M. Mateen Yaqoob The University of Lahore Spring 2014.
Lecture Set 4 Programming the 8051.
1 Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
What is a program? A sequence of steps
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Revised: Aug 1, EE4390 Microprocessors Lessons 11, 12 Advanced Assembly Programming.
Chapter 8 String Operations. 8.1 Using String Instructions.
Chapter 14 Functions.
Unit 1 Instruction set M.Brindha AP/EIE
The Forth Language CSC 507 – Roy Ford November 22, 2005.
3.Instruction Set of 8085 Consists of 74 operation codes, e.g. MOV
The Processor and Machine Language
Mano and Kime Sections 7-6 – 7-8
Processor Organization and Architecture
Forth A stack language.
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
8051 ASSEMBLY LANGUAGE PROGRAMMING
COMPUTER ORGANIZATION AND ARCHITECTURE
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Lecture 3 - Instruction Set - Al
Return Stack Lab 8.
Chapter 10 Instruction Sets: Characteristics and Functions
Chapter 4 The Von Neumann Model
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

A Programming Language for the FC16 Forth Core WHYP A Programming Language for the FC16 Forth Core

WHYP Pronounced “whip” “Words to Help You Program” Subroutine-threaded Forth for Embedded Systems 68HC11 (16-bit) 68332 (32-bit) 68HC12 (16-bit)

WHYP is developed from scratch in the new book: Design of Embedded Systems Using 68HC12/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

FORTH is a programming languages that --- 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

Introducing WHYP (Forth) 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) If you type a WHYP word and press <enter>, the word will be executed (interpret mode) If you type a number (e.g. 6) and press <enter>, 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.

The Structure of WHYP PC Target 68HC12 C++ Program Kernel: Dictionary: --- --- Serial Line LOOP BSR INWDY --- --- JSR 0,Y --- --- send address BRA LOOP --- --- F82C display F82C --- --- F82C ----- --- --- ----- ----- ----- Screen ----- C:\>whyp RTS ok display

WHYP Arithmetic Operators 7 9 + . 8 5 - . 4 7 * . 8 3 / . 8 3 /MOD . .

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

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 )

WHYP on the FC16

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

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)

Stack Manipulation Words Colon Definitions : 2DUP ( a b -- a b a b ) OVER (0004) \ a b a OVER (0004) ; \ a b a b

Memory Access Words Fetch Store \ 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) ;

RAM Module

Return Stack Words To-R R-From R-Fetch R-From-Drop : >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) ;

Arithmetic Words Plus w3 = w1 + w2 minus w3 = w1 - w2

Arithmetic Words One-plus w2 = w1 + 1 One-minus w2 = w1 - 1

Logical Words Bitwise AND Bitwise OR Bitwise XOR One’s complement : AND ( w1 w2 -- w3 ) ANDD (0015) ; Bitwise OR : OR ( w1 w2 -- w3 ) ORR (0016) ; Bitwise XOR : XOR ( w1 w2 -- w3 ) XORR (0017) ; One’s complement : INVERT ( w1 -- w2 ) INVERT (0014) ;

Logical Words TRUE = X“FFFF” FALSE = X“0000” : TRUE (-- w ) ONES (0020) ; FALSE = X“0000” : FALSE (-- w ) ZEROS (0021) ;

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 < ( n1 n2 -- f ) (“less-than”) > ( n1 n2 -- f ) (“greater-than”) = ( n1 n2 -- f ) (“equals”) <> ( n1 n2 -- f ) (“not-equals”) <= ( n1 n2 -- f ) (“less-than or equal”) >= ( n1 n2 -- f ) (“greater-than or equal”) 0< ( n -- f) (“zero-less”) 0> ( n -- f) (“zero-greater”) 0= ( n -- f) (“zero-equal”) U< ( u1 u2 -- f ) (“U-less-than”) U> ( u1 u2 -- f ) (“U-greater-than”) U<= ( u1 u2 -- f ) (“U-less-than or equal”) U>= ( u1 u2 -- f ) (“U-greater-than or equal”)

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

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

x = 1; i = 2; WHILE (i <= n) { x = x * i i = i + 1 } factorial = x

FC16 Relational Operator Words Zero-equals -- true if T = 0 (NOT) : 0= ( n -- f ) zeroequal (0022) ; Zero-less-than -- true if T < 0 : 0< ( n -- f ) zeroless (0023) ; Zero-greater-than -- true if T > 0 : 0> ( n -- f ) DUP 0= \ n f1 SWAP 0< \ f1 f2 OR NOT ;

Relational Operator Words U-greater-than -- true if u1 > u2 : U> ( u1 u2 -- f ) ugt (0024); when ugt if N > T then ones; else zeros; endif; U-less-than -- true if u1 < u2 : U< ( n1 n2 -- f ) ult (0025); equal-to -- true if n1 = n2 : = ( n1 n2 -- f ) eq (0026) ; Implement these instructions directly In Funit

Relational Operator Words U-greater-than-or equal -- true if u1 >= u2 : U>= ( u1 u2 -- f ) ugte (0027) ; U-less-than-or equal -- true if u1 <= u2 : U<= ( u1 u2 -- f ) ulte (0028) ; not-equal-to -- true if n1 /= n2 : <> ( n1 n2 -- f ) neq (0029) ;

Relational Operator Words greater-than -- true if n1 > n2 : > ( n1 n2 -- f ) gt (002A) ; less-than -- true if n1 < n2 : < ( n1 n2 -- f ) lt (002B) ; use IEEE.std_logic_arith.all; variable avs, bvs: signed (width-1 downto 0); In Funit16

use IEEE.std_logic_arith.all; variable avs, bvs: signed (width-1 downto 0); variable y_tmp: STD_LOGIC_VECTOR (width-1 downto 0); for i in 0 to width-1 loop true(i) := '1'; false(i) := '0'; av(i) := a(i); bv(i) := b(i); avs(i) := a(i); bvs(i) := b(i); end loop;

In Funit16 when “101010" => if (avs > bvs) then y <= true; else y <= false; end if;   when “101011" => if (avs < bvs) then y <= true;

Relational Operator Words greater-than-or-equal -- true if n1 >= n2 : >= ( n1 n2 -- f ) gte (002C) ; less-than-or-equal -- true if n1 <= n2 : <= ( n1 n2 -- f ) lte (002D) ;

Branching Words if ( f -- ) JZ (0102) -- else JMP (0101) then

Branching Words begin -- while ( f -- ) JZ (0102) repeat JMP (0101)

Branching Words begin -- until ( f -- ) JZ (0102)

Branching Words begin -- again JMP (0101)

Looping Words for (cnt -- ) >R --- next DRJNE