We have always had rudimentary inline assembly support in ARM BASIC. When adding multitasking support we expanded that capability. Originally the keyword __ASM__(code) would compile that 16 bit code instruction into the BASIC program. Now __ASM__(code) also supports 32 bit instructions, and __ASM32__(word) has been added to emit a word aligned 32 constant, typically used by PC relative instructions.

To make code more human readable we have published a #include 'able file to define the most used assembly ops. The ASMinlineBASIC.bas file has been expanded by some of our users for even more ops. This file is included in the setupBASIC installer, or you can take a peak at it here

Here is an example of the code used to do context switching in our Multitask.bas example

' interrupt stack frame    ARM INT pushes 8, INTERRUPT SUB pushes 8 + LR
#define INT_FRAME   (17-1)          
#define RETURN_PC   ((INT_FRAME-1)*4)
#define RETURN_INT  &HFFFFFFF9      '  when returns to this value -- interrupt return
#define INIT_PSR    &H61000000      '  bit 24 required for M3/ M4, seems don't care on M0

'...

        ASM_LDR_SPI(r7,RETURN_PC)   ' r7 now has PC for main
        saveMainPC = __ASM__        ' save it in saveMainPC

        save_r7 = task0PC
        ASM_STR_SPI(r7,RETURN_PC)   ' set the return to task0:

        ASM_MOV(r7,sp)              ' r7 now has value of SP
        save_r7 = __ASM__           ' calculating the next (index) clobbers r7, so save it
        taskSP(0) = save_r7         ' save current SP in taskSP(0)

You will notice, the __ASM__ construct, which is also new. The BASIC expression analyzer leaves the value of the expression in the ARM register R7, which is a good way to pass values to inline assembly. So in reality __ASM__ does nothing code wise, I have been known to be good at that.

Next Post Previous Post

  0