
---------------------------------------------------------------
          Mecrisp-Stellaris with Register Allocator
          Released under GPL3
---------------------------------------------------------------

This is highly experimental software !

It should look and feel like the mainstream Mecrisp-Stellaris,
but with a very important difference:

This time, it contains an analytical compiler which keeps track
of the top five stack elements and maps them to registers
whenever possible.

Five targets are available: 
KL25Z128 & LPC1114FN28 (Cortex M0), ARM Linux and LM4F120 & TM4C1294 (Cortex M4).

For M4, you can flash your Stellaris or Tiva Launchpad with the included binary.

For M0, you have three possibilities:

  You can either flash the srec file to your Freedom board
  or make the thumbulator and type
  "thumbulator mecrisp-stellaris-kl25z128.bin".

  You can also use a LPC1114FN28 chip and flash its hex file.

To dive in, you should load the disassembler and see
definitions you have just compiled.

Two examples, on M0:

: >gray ( u -- x ) dup 1 rshift xor ;  ok.
see >gray
00006B38: 0873  lsrs r3 r6 #1
00006B3A: 405E  eors r6 r3
00006B3C: 4770  bx lr
 ok.


: bitexp ( u -- u )  ok.
  ok.
  \ Returns an integer value equivalent to  ok.
  \ the exponential. For numbers > 16,  ok.
  \ bitexp(x) approx = 2^(x/8 + 1)  ok.
  ok.
  \ B(E(x)) = x for 16 <= x <= 247.  ok.
  ok.
  dup 247 u>  \ Overflow ?  ok.
  if drop $F0000000  ok.
  else  ok.
  ok.
    dup 16 u<= if 1 rshift  ok.
               else  ok.
                 dup ( u u )  ok.
                 7 and 8 or ( u b )  ok.
                 swap ( b u )  ok.
                 3 rshift 2 - lshift  ok.
               then  ok.
  ok.
  then  ok.
  ok.
  1-foldable ;  ok.
  ok.
see bitexp
00006BA2: 2EF7  cmp r6 #F7
00006BA4: B500  push { lr }
00006BA6: D902  bls 00006BAE
00006BA8: 26F0  movs r6 #F0
00006BAA: 0636  lsls r6 r6 #18
00006BAC: E00C  b 00006BC8
00006BAE: 2E10  cmp r6 #10
00006BB0: D801  bhi 00006BB6
00006BB2: 0876  lsrs r6 r6 #1
00006BB4: E008  b 00006BC8
00006BB6: 0033  lsls r3 r6 #0
00006BB8: 2007  movs r0 #7
00006BBA: 4003  ands r3 r0
00006BBC: 2008  movs r0 #8
00006BBE: 4303  orrs r3 r0
00006BC0: 08F6  lsrs r6 r6 #3
00006BC2: 3E02  subs r6 #2
00006BC4: 40B3  lsls r3 r6
00006BC6: 461E  mov r6 r3
00006BC8: BD00  pop { pc }

Note that it compiles bitexp without any stack movements at all.

Please contact me to let me know your experience with
the new compiler under the hood:

Matthias Koch
m-atthias@users.sf.net
