ep32 metacompiler 2012 fig taiwan conference february 17, 2012 chen-hanson ting

18
eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Upload: theresa-bell

Post on 17-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Metacompiler

2012 FIG Taiwan Conference

February 17, 2012

Chen-Hanson Ting

Page 2: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Summary eP32 Metacompiler eP32 Assembler eP32 Kernel eP32 Interpreter eP32 Compiler eP32 Simulator Demonstration

Page 3: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Metacompiler eP32 Metacompiler has

these components: Metacompiler Assembler eP32 Kernel eForth Interpreter eForth Compiler eP32 Simulator

Page 4: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Metacompiler Generate an eP32 FORTH

system on F# FORTH system

Construct the eP32 dictionary in a data array.

The data array is imported to the ram_memory.vhd to initialize the eP32_chip.

Page 5: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Metacompiler

FORTH uses commands , (comma) and C, (c-comma) to build new words in dictionary

Metacompiler redefines , and C, to build new target words in an array which will become the dictionary in target system

Page 6: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Target Image

CREATE ram 8000 ALLOT: RAM@ ram + @ ;: RAM! ram + ! ;

Page 7: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Assembler

Assemble 1-5 instructions in a 32 bit program word

eP32 has two types of instructions:

Long Instructions00 cccccc aaaaaa aaaaaa aaaaaa aaaaaaShort Instructions00 cccccc cccccc cccccc cccccc cccccc

Page 8: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Short Instructions: INST CONSTANT DOES> R> @ ,I ;08 spread inst ldrp 09 spread inst ldxp ( 0A spread inst ldi) 0B spread inst ldx0C spread inst strp 0D spread inst stxp 0E spread inst rr8 0F spread inst stx10 spread inst com 11 spread inst shl 12 spread inst shr 13 spread inst mul14 spread inst xor 15 spread inst and 16 spread inst div 17 spread inst add18 spread inst popr 19 spread inst xt 1A spread inst pushs 1B spread inst over1C spread inst pushr 1D spread inst tx ( 1E spread inst nop ) 1F spread inst pops

Page 9: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Long Instructions

: jump CONSTANT DOES> anew R> FFFFFF AND @ OR #, ;

0 JUMP bra2000000 JUMP bz3000000 JUMP bc4000000 JUMP call5000000 JUMP next

Page 10: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Structured Assembler : if h @ 0 bz ; ( 5F80000 )

: ifnc h @ 0 bc ; ( 5F40000 )

: skip h @ 0 bra ; ( 5FC0000 )

: then begin OVER ram@ OR SWAP ram! ;

: else skip SWAP then ;

: while if SWAP ;

: whilenc ifnc SWAP ;

: repeat bra then ;

: again bra ;

: aft ( a -- a' a" )

DROP skip begin SWAP ;

Page 11: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Low/High Level Words : CODE makeHead begin .head CONSTANT

DOES> R> @ call ;: :: makeHead begin .head CONSTANT

DOES> R> @ call ;

In eP32 system, code words and colon words are the same, all making subroutine calls.

Page 12: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Kernel FORTH has been always a Virtual

Machine, which interprets and compiles FORTH words.

Even as eP32 is a true FORTH engine, it still must be converted to a Virtual FORTH machine, with a kernel of FORTH words implemented in eP32 machine instructions.

Page 13: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eForth Interpreter Terminal IO Common utility words Multplication and division Memory read/write Number to text conversion Printing words Text to number conversion Text input Error handling Text interpreter

Page 14: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eForth Compiler

Command compiler Structural compiler Tools Defining words Boot up

Page 15: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Simulator

Arrays and variables Finite state machine Machine instruction

simulator User interface

Page 16: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

eP32 Simulator

Page 17: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Simulation Commands C: Execute next cycle S: Display registers and

stacks D: Display 8 program

wordsa M: Display memorya P: Assign next program

address a G: Execute till address is GRUN: Single stepping

Page 18: eP32 Metacompiler 2012 FIG Taiwan Conference February 17, 2012 Chen-Hanson Ting

Demonstration

Metacompile a eP32 eForth system

Examine symbol table Examine program memory Invoke simulator Compare simulator results and

actual eP32 results