Skip to main content

__ASM__

Syntax


__ASM__   ( expression )

__ASM32__ (expression)

Description


__ASM__ tells the compiler to compile the expression into the program

expression is a number, and represents the 16 bit opcode that is added to the code.  If the value of expression is a 32 bit constant (>= &H10000), then 2 16 bit values are added to the code. This handles long jumps

We currently don't have a symbollic assembler and the user has to generate the expression that represents an ARM Thumb opcode.  Details on the Thumb opcodes can be found here .  Recently we have created a macro library that covers ARM instructions we have used or think are commonly used.  It will be part of the release, or can be found at the forum .

__ASM32__ will evaluate as a 32 bit word and is aligned to a word boundary and added to the code. The alignment is done by inserting a NOP if necessary, but the intention of this is for PC relative constants which must be word aligned. While it can be used for general assembly opcodes the simple __ASM__ is better.

To save some needed assembly statements, __ASM__ can now be used as an rvalue.  This actually does nothing and the result is whatever is in R7

A number of ARM instructions have been encoded by the #include file ASMinlineBASIC.bas

Example

#include
"ASMinlineBASIC.bas" ' get macros for most ARM instructions

...

ASM_LDR_SPI(7,60) ' r7 now has PC for routine that INTERRUPT SUB interrupted

savePC
=__ASM__
' save it in savePC

...

ASM_LDR_PC(6,2)
' load R6 with PC relative constant &H12345678

__ASM32__(&H12345678)

***  under the hood --***

For the Cortex parts, the BASIC compiler saves the value computed in the last statement in R7.  These registers uses are subject to change.

R4 is used in index operations and pointers

R6 is normally the second operand in expression evaluation, and is combined with R7 to produce the last value of an expression

R5 is used in some string operations

R9 can be used as a temporary variable in complex expressions that require intermediate values to be saved on the stack.

Differences from other BASICs

\

  • no equivalent in Visual BASIC
  • no equivalent in PBASIC