Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l...
Transcript of Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l...
![Page 1: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/1.jpg)
OCAPICprogramming PIC microcontrollers
using Objective Caml
Philippe Wang1/20
& Benoît Vaugon
ocaml meeting 2011Paris, April 15th
![Page 2: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/2.jpg)
OCAPICprogramming PIC microcontrollers
using Objective Caml
Philippe Wang1/20
& Benoît Vaugonsupervisor developer
![Page 3: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/3.jpg)
OCAPICprogramming PIC microcontrollers
using Objective Caml
1/20picture from http://fr.wikipedia.org/wiki/Fichier:4pics.jpg
![Page 4: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/4.jpg)
OUTLINE
What PIC microcontrollers (µC) are.
What we did with a PIC18 µC.
How we did it.
What is OCaml in OCAPIC?
Conclusion.
2/20
![Page 5: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/5.jpg)
PIC microcontrollers
3/20picture from http://en.wikipedia.org/wiki/File:PIC16CxxxWIN.JPG
![Page 6: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/6.jpg)
a tiny die(proc+RAM+flash)
PIC microcontrollers
a PIC µC
picture from http://en.wikipedia.org/wiki/File:PIC16CxxxWIN.JPG
large connectors
3/20
![Page 7: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/7.jpg)
PIC microcontrollers
programmable
low-energy consumption
low-cost (~ 2 €)
amateur circuits + domestic appliances
no operating system ⇒ no segmentation fault!
picture from http://en.wikipedia.org/wiki/File:PIC16CxxxWIN.JPG 3/20
![Page 8: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/8.jpg)
PIC18 microcontrollers
RISC 8-bit architecture
Flash memory: 4 to 128 kB
RAM: 256 B to 4kB
Speed: 8 to 16 MIPS
4/20picture from http://fr.wikipedia.org/wiki/Fichier:4pics.jpg
![Page 9: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/9.jpg)
PIC18 microcontrollers
8-bit architecture like old times...
Flash memory: 4 to 128 kB
RAM: 256 B to 4kB
Speed: 8 to 16 MIPS like old times...
4/20picture from http://fr.wikipedia.org/wiki/Fichier:4pics.jpg
![Page 10: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/10.jpg)
PIC18 microcontrollers
8-bit architecture like old times...
Flash memory: 4 to 128 kB stores the program
RAM: 256 B to 4kB
Speed: 8 to 16 MIPS like old times...
4/20picture from http://fr.wikipedia.org/wiki/Fichier:4pics.jpg
![Page 11: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/11.jpg)
PIC18 microcontrollers
8-bit architecture like old times...
Flash memory: 4 to 128 kB stores the program
RAM: 256 B to 4kB wow... that’s tight !
Speed: 8 to 16 MIPS like old times...
4/20picture from http://fr.wikipedia.org/wiki/Fichier:4pics.jpg
![Page 12: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/12.jpg)
PIC18 microcontrollers
8-bit architecture
Flash memory: 4 to 128 kB
RAM: 256 B to 4kB wow... that’s tight !
Speed: 8 to 16 MIPS
4/20picture from http://fr.wikipedia.org/wiki/Fichier:4pics.jpg
![Page 13: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/13.jpg)
APP Example
5/20picture taken at JFLA 2011
![Page 14: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/14.jpg)
APP Example
5/20
a 2-player strategy game
human versus computer
a board with 24 push-buttons + wiring
an LCD display + a PIC18 µC + a battery
picture taken at JFLA 2011
![Page 15: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/15.jpg)
APP Example
6/20picture taken at JFLA 2011
![Page 16: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/16.jpg)
APP Example
6/20picture taken at JFLA 2011
![Page 17: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/17.jpg)
APP Example
6/20
PIC18F4620
LCD display
wires
homemade circuitpictures taken at JFLA 2011
![Page 18: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/18.jpg)
APP Example
humans tend to lose...
6/20pictures taken at JFLA 2011
![Page 19: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/19.jpg)
APP Example
humans tend to lose...
6/20
implementation in OCaml
$ wc -l *.ml* 78 display.ml 156 goblet.ml 256 grid.ml 117 ia.ml 60 stacks.ml 14 types.mli 681 total
but how to program PIC µCs in OCaml?
➙
picture taken at JFLA 2011
![Page 20: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/20.jpg)
a new backend for OCaml
8-bit architectureFlash memory: 4 to 128 kBRAM: 256 B to 4kB wow... that’s tight !Speed: 8 to 16 MIPSno operating system
for programming PIC18 µClet’s keep in mind what PIC18 µC are
OCAPIC
OCAPIC provides (among other things) an OCaml VM on a PIC, to run them all
7/20
![Page 21: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/21.jpg)
OCamlmultiparadigm, high-level featuresautomatic safe memory managementcomplex RT lib (e.g., Pervasives.compare)
PIC & OCaml
PIC18F46203968 registers of 1 byte (➙ RAM)8-bit RISC architecture64 kB of flash memory
8/20
![Page 22: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/22.jpg)
OCamlmultiparadigm, high-level featuresautomatic safe memory managementcomplex RT lib (e.g., Pervasives.compare)
PIC & OCaml
PIC18F46203968 registers of 1 byte (➙ RAM)8-bit RISC architecture64 kB of flash memory
8/20
tight resources
rich language
![Page 23: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/23.jpg)
Assembly languageCompiled languages
Basic (BASIC84plus)C (sdcc, SIXPIC, MCC18, ...)Forth (PicForth)
Interpreted languagesBasic (BasicStamps), Forth (FlashForth)
Virtual MachinePICOBIT (a Scheme VM for PIC)
PIC microcontrollerswithout OCaml
SAMPLE:tblrd*+addwf FSR0L, Wrcall SUB_PRGMbtfsc STATUS, Cincf FSR0H, Freturn
9/20
programming
![Page 24: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/24.jpg)
WITH OCamlProgramming PIC microcontrollers
OCAPIC usage overview 10/20
![Page 25: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/25.jpg)
OcAPIC
OCamlCleana tool for eliminating dead code
BCtranscompress bytecode for PIC (take back zeros)
OCaml Virtual Machineimplemented in PIC18 ASM
(+ a PIC environment simulator)
a new backend for OCaml& a set of tools
11/20
![Page 26: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/26.jpg)
OCamlClean
reduce heap occupation& remove unused closures (a lot from libraries)‣ reduce bytecode size & faster initializationreduce indirections (closures globalization)‣better performance
empty bytecodefor empty programs
12/20
takes a binary, gives back a lighter binary
(can be used in casual programming)
![Page 27: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/27.jpg)
Compression with BCTRANS(OCaml bytecode ➙ .HEX)
13/20
converts an OCaml binary into PIC data
take back zeros (divides size by 3.5)OCaml bytecode binaries have a lot of zeros for good reasons, but it’s a huge waste for PIC µCchange heap initialization techniquereplace computations by a simple copyexternal (ASM) functions link resolution
![Page 28: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/28.jpg)
OCAML VM in PIC ASMOCAMLRUN on a PIC
14/20
wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total
memory garbage collector• a simple Stop&Copy (150 lines of ASM)• a full cycle runs in less that 1.5ms (RAM is small) uniform data representation, using 16 bits• 15-bit integers, repr. as in orig. OCaml (tag on 1 bit)• block repr. ~ as in original OCaml: tag & size & data
![Page 29: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/29.jpg)
part that can’t be in OCaml: stdlib.asmArithmetic operators, Pervasives.compare, ...
some OCaml modules are copiedArray, ArrayLabels, CamlinternalLazy, CamlinternalMod, Char, Hashtbl, Int32, Int64, Lazy, List, ListLabels, MoreLabels, OO, Queue, Set, Sort, Stack, StdLabels, String, StringLabels
some OCaml modules are modifiedBuffer+ , CamlinternalOO+ , Gc+, Map+, Obj+, Pervasives∗ , Random, Printf∗, Std_exit, Stream, Sys∗,
some OCaml modules are left behindArg, Complex, Callback, Digest, Filename, Format, Genlex, Marshal, Nativeint, Parsing, Printexc, Scanf, Weak
wc -l stdlib.asm 6757 stdlib.asm (+ ~180 lines of OCaml)
OCAPIC Library
15/20
standard library
![Page 30: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/30.jpg)
OCAPIC Library
16/20
PIC specific librariesexternal read_reg : reg -> int = "caml_pic_read_reg";;(** [read_reg reg] reads value of a Special Function Register [reg]. Return value between 0 and 255. *)
external write_reg : reg -> int -> unit = "caml_pic_write_reg";;(** [write_reg reg value] writes value in the Special Function Register [reg]. [value] should be between 0 and 255. *)
external set_interruption_handler : (bit -> unit) -> unit = "caml_set_interruption_handler";;(** Register an interruption handler. *)
external clear_interruption_handler : unit -> unit = "caml_set_interruption_handler";;(** Remove the interruption handler. *)
PIC I/O
interruptions
![Page 31: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/31.jpg)
a tiny die
PIC microcontrollers
a PIC µC
picture from http://en.wikipedia.org/wiki/File:PIC16CxxxWIN.JPG
large connectors
3/20
![Page 32: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/32.jpg)
OCAPIC Library
16/20
PIC specific librariesexternal read_reg : reg -> int = "caml_pic_read_reg";;(** [read_reg reg] reads value of a Special Function Register [reg]. Return value between 0 and 255. *)
external write_reg : reg -> int -> unit = "caml_pic_write_reg";;(** [write_reg reg value] writes value in the Special Function Register [reg]. [value] should be between 0 and 255. *)
external set_interruption_handler : (bit -> unit) -> unit = "caml_set_interruption_handler";;(** Register an interruption handler. *)
external clear_interruption_handler : unit -> unit = "caml_set_interruption_handler";;(** Remove the interruption handler. *)
PIC I/O
interruptions
![Page 33: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/33.jpg)
OCAPIC Library
17/20
PIC specific librariesmodule MyDisplay = Lcd.Connect (struct let bus_size = Lcd.Four (* databus mode *) let e = Pic.LATD0 (* command connector *) let rs = Pic.LATD2 let rw = Pic.LATD1 let bus = Pic.PORTC (* databus port *)end);;MyDisplay.init ();;MyDisplay.config ();;MyDisplay.print_string "Hello world";;
let (ic : t in_channel) = Serial.open_in () in while true do match Serial.receive ic with | Clear -> clear () | Moveto (l, c) -> moveto l c | Int i -> print_int i | Text t -> print_string tdone
LCD display
serial conn.
![Page 34: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/34.jpg)
APP Example
6/20
PIC18F4620
LCD display
wires
homemade circuitpictures taken at JFLA 2011
![Page 35: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/35.jpg)
OCAPIC Library
17/20
PIC specific librariesmodule MyDisplay = Lcd.Connect (struct let bus_size = Lcd.Four (* databus mode *) let e = Pic.LATD0 (* command connector *) let rs = Pic.LATD2 let rw = Pic.LATD1 let bus = Pic.PORTC (* databus port *)end);;MyDisplay.init ();;MyDisplay.config ();;MyDisplay.print_string "Hello world";;
let (ic : t in_channel) = Serial.open_in () in while true do match Serial.receive ic with | Clear -> clear () | Moveto (l, c) -> moveto l c | Int i -> print_int i | Text t -> print_string tdone
LCD display
serial conn.
![Page 36: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/36.jpg)
Benchmarks
~400,000 VM instructions/second~25 machine cycles/VM instruction(~18 for a standard processor)PICOBIT runs 37,000 VM instructions/second
less by 11 times, but for a different bytecode
64 kB of flash memory on PIC18F4620Interpreter: 4954 B (7.6%)Runtime library: ≤ 4254 B (≤ 6,5%)Bytecode: up to 55kB (86%)
execution speed
flash memory
occupation
18/20
OCAPIC+ PIC18F4620
![Page 37: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/37.jpg)
ConclusionFull OCaml frontend & Good performancethanks to a virtual machine! (+ a set of tools)
OCAPIC works with any PIC18 (but check the memory size)
OCamlClean was necessary to allow the use of OOP(but not necessary for small programs without OOP)
Other ideas• make other languages target OCaml VM• port OCaml VM on other architectures• try other garbage collection algorithms• try external RAM
19/20http://www.algo-prog.info/ocaml_for_pic/
![Page 38: Paris, April 15th OCAPIC · 2011-05-05 · OCAML VM in PIC ASM OCAMLRUN on a PIC 14/20 wc -l interp.asm runtime.asm 2556 interp.asm 368 runtime.asm 2924 total memory garbage collector](https://reader033.fdocuments.us/reader033/viewer/2022043009/5f9c060c86dd4b4e3c671ab2/html5/thumbnails/38.jpg)
picture taken at JFLA 2011
Thanks!
20/20
don’t m!s " demo session
$! a%ernoon ;-)
Any questions?