Asm-endAsm

Insert assembler sourcecode at the current position. Syntax:

  • Asm
    • assembler-source code
  • endAsm

Inline-Assembler

Strings and comments of the inline assembler source code follow the same LunaAVR syntax. Comments in „normal“ assembler source code are marked with a ; and in inline assembler with a ' or //. Strings are always enclosed with double quotes.

General

Some additional features are implemented in addition to the standard opcodes of the respective controller:

Labels in the assembler source code

The labels in the luna source code are associated with the class they were created. E.g. a label „mylabel“ in the main program will be expanded to „classAvrMylabel“ and „mylabel“ in its own class „myclass“ to „classMyclassMylabel“. This also applies to labels in the inline assembler source code. This name expansion is important to avoid conflicts between different name spaces and to enable access from within the luna source code to the inline assembler labels.

Example 1

' somewhere in the main program
Asm
  classAvrMyLoop:
    nop
    rjmp classAvrMyLoop
endAsm

Example 2

' somewhere in the main program
Asm
  MyLoop:             'will be expanded to  "classAvrMyLoop"
    nop
    rjmp classAvrMyLoop
endAsm

Expressions/Commands

Expressions and operators can be used in conjunction with constants.
The following additional commands are implemented (only in the assembler sourcecode):

Command Description Example
.equ create a constant .equ var = 123.45
.set create/assign a constant .set var = 123.45
.def Alias .def temp = R16
.device set the avr controller type .device atmega32
.importClass import avr class. sets all defines and constants of the selected avr controller inclusive .device .importClass atmega32
.importObject import a library object .importObject Macro_Delay
.importUsedObjects imports all in the source code used libraries objects .importUsedObjects
.cseg select flash segment .cseg
.dseg select sram segment .dseg
.eseg select eeprom segment .eseg
.org Sets the pointer of the actual active segment to a specific value .org intVectorSize
low()/lo8() Low-Byte of a value ldi R16,low(33000)
high()/hi8() High-Byte of a value ldi R16,high(33000)
byten() Byte of a value 1-4 ldi R16,byte1(33000)
single()/float() Ieee Single-format of a value .set value = single(33000)
.if .else .endif Preprocessor case differentiation on assembler level
defined() check whether there is a symbol defined.

Example 3

' call assembler routine
call example
' Somewhere in the program code
Asm
  classAvrexample:
    add  R16,R17
    ori  R16,&h33
    ldi  R16,(1<<3) or (1<<7)   ; Set bit 3 and 7
    ldi  ZL,lo8(classAvrexample)
    ldi  ZH,hi8(classAvrexample)
    inc  R17
    ret
endAsm