User Tools

Site Tools


en:pfw:assemblers_rp2040-assembler

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:pfw:assemblers_rp2040-assembler [2023-09-04 18:11] – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1en:pfw:assemblers_rp2040-assembler [2023-10-02 17:04] (current) – [Two usage examples] willem
Line 1: Line 1:
 +{{pfw:banner.png}}
 +====== Assembler for RP2040 ======
 +
 +===== The idea =====
 +
 +A compact Forth-style macro assembler with an efficient literal pool mechanism for the RP2040.\\
 +A Forth-style assembler uses all the capabilities of the Forth interpreter and assembles opcodes in between.\\
 +An example:
 +<code>
 +code SQUARED    ( +n -- +n^2 )
 +    tos tos muls,  next,
 +end-code
 +</code>
 +===== Implementation =====
 +
 +The example code asumes a 32-bit machine that has 16-bit & 32-bit compile actions. 
 +It is also asumed that the code runs in RAM as noForth T on the RP2040 does.
 +Because the Thumb-2 opcodes of the ARMv6-M use a RISC like architecture, macros
 +are added to make assembly a bit more easy.
 +An implementation example for ''%%CODE%%'' and ''%%END-CODE%%'' is showed too. Missing words in Generic Forth are:
 +
 +<code forth>
 +(*          ( "ccc" -- )        - Skip all text until *) is found
 ++TO         ( n "name" -- )     - Add n to the contents of the value "name"
 +VOCABULARY  ( "name" -- )       - Define a named wordlist
 +</code>
 +
 +==== All Thumb2 instructions ====
 +
 +<code forth>
 +
 +✦ Two low register opcodes
 +    ands,       eors,       adcs,       sbcs,       rors,       tst,
 +    neg,        cmn,        orrs,       muls,       bics,       mvns,
 +    sxth,       sxtb,       uxth,       uxtb,       rev,        rev16,
 +    revsh,      lsls,       lsrs,       asrs,       movs,       cmp,
 +    
 +✦  Two all register opcodes
 +    add,        mov,        cmp,
 +    
 +✦ Three low register opcodes
 +    adds,       subs,       str,        strb,       strh,       ldrb,
 +    ldrh,       ldr,        ldrsb,      ldrsh,
 +
 +✦ Two low register & 3-bits immediate
 +    adds,       subs,       rsbs,
 +
 +✦ Two low register & 5-bits immediate
 +    lsls,       lsrs,       asrs,       str,        strb,       strh,   
 +    ldr,        ldrb,       ldrh,
 +
 +✦ One low register & 7-bits immediate (RP-specific)
 +    add,        subs,       sub,
 +
 +✦ One low register & 8-bits immediate
 +    movs,       cmp,        str, (rp)   ldr, (rp)   ldr,        add, (rp)
 +    push,       pop,        bkpt,       udf,        svc,        adr,
 +    stm,        ldm,        adds,       subs,
 +
 +✦ Various 16-bit opcodes
 +    noop,       nop,        yield,      wfe,        wfi,        sev,
 +    cpsie,      cpsid,      bx,         blx,
 +
 +✦ Fourteen jump instructions
 +    =?          cs?         neg?        vs?         u>?         <?
 +    >?          no
 +
 +✦ Control structures
 +    if,         else,       then,       ahead,
 +    begin,      while,      repeat,     again,      until,
 +    
 +✦ Literal pool additions
 +    ALIGN,      CODE>       POOL,       APOOL,      ##
 +
 +✦ Assembler macros
 +    ALIGN,      ##          POOL,       APOOL,      )+
 +    -)          NEXT,
 +</code>
 +
 +==== Two usage examples ====
 +
 +<code>
 +code LSHIFT ( x1 +n -- x2 )
 +    day tos movs,       \ 1 - +n to DAY
 +    tos  sp )+ ldr,     \ 2 - pop X1 to TOS
 +    tos day lsls,       \ 1 - Shift TOS DAY positions left
 +    next,               \ 6 
 +end-code
 +
 +code KEY?)  ( -- f )
 +    40034018 ,          \ UART0 UARTFR 
 +code>
 +    sun  w ) ldr,       \ Read UARTFR to SUN
 +    tos  sp -) str,     \ Push stack
 +    tos  sun ) ldr,     \ Read flags
 +    tos 1B # lsls,      \ Build flag out of bit-4
 +    tos 1F # asrs,      \ Extend sign
 +    tos tos mvns,       \ Invert flag
 +    next,
 +end-code
 +</code>
 +
 +<code></code>
 +| File name | Purpose | in Dropbox (external link) |
 +| [[https://www.dropbox.com/s/glvdl0runl65u3t/Thumb%20assembler%20doc%20v2.pdf?dl=1|Thumb assembler doc v2.pdf]] | Documentation | [[https://www.dropbox.com/s/glvdl0runl65u3t/Thumb%20assembler%20doc%20v2.pdf?dl=0|Assembler documentation]] |
 +| [[https://www.dropbox.com/s/jaw8dalna8sodut/RP2040-asm%20uni.f?dl=0|RP2040-asm uni.f]] | RP2040 assembler | [[https://www.dropbox.com/s/0ubyr344j7a1q7k/noForth-T-das.f?dl=0|noForth RP2040 assembler]] |
 +| [[https://www.dropbox.com/s/2g4glx7gcnmuvyl/RP2040-asm-extensions%20uni.f?dl=0|RP2040-asm-extensions uni.f]] | RP2040 ass. extensions | [[https://www.dropbox.com/scl/fi/65wbh85v95rvh4uoo5rtd/T-asm-ext.f?rlkey=v8cpj3mr45oz9ou4v3apyi5w2&dl=0|noForth assembler ext.f]] |
 +
 +==== Contributions ====
 +
 +<html><h2 style="background-color:yellow">Alternative Implementations</h2></html>
 +
 +
 +
 +[[en:pfw:welcome|Back to PFW page]]