Der alte AVRasm wurde ersetzt durch einen internen Assembler und bietet dadurch mehr asm Komfort.
# Asm-Bloecke / Asm blocks
**DE** Ein Asm-Block steht zwischen `asm;` und `endasm;`. Der Compiler macht ihn bequemer als frueher, ohne dass alter Code sich aendert.
**EN** An asm block stands between `asm;` and `endasm;`. The compiler makes it more comfortable than before; old code stays unchanged.
## 1. Pascal-Namen / Pascal names
Code
const Limit : byte = 100;
var Count : byte;
...
asm;
LDS _ACCA, Count // Variable einer Unit -> Unit.Count
CPI _ACCA, Limit // Konstante -> 100
BREQ done
INC _ACCA
done:
STS Count, _ACCA
endasm;
- **DE** Ein Variablenname im Operanden wird zu `Unit.Name`, eine Konstante mit Zahl zu ihrem Wert (auch in `LOW(..)` / `HIGH(..)`). Die alte Schreibweise (`Unit.Name`, `%.Name`) gilt weiter.
- **EN** A variable name in an operand becomes `Unit.Name`, a constant with a number becomes its value (also inside `LOW(..)` / `HIGH(..)`). The old way (`Unit.Name`, `%.Name`) stays valid.
- **DE** `LOW(x)` / `HIGH(x)` (x ein Name oder eine Zahl, am Ende des Operanden) setzt der Compiler in `x AND 0FFh` / `x SHRB 8` um; der Assembler kennt `LOW` / `HIGH` selbst nicht.
- **EN** `LOW(x)` / `HIGH(x)` (x a plain name or number, at the end of the operand) become `x AND 0FFh` / `x SHRB 8`; the assembler itself does not know `LOW` / `HIGH`.
- Aus / off: Umgebungsvariable `AVRCO_NOASMNAMES=1`.
## 2. Gleiche Labels / same labels
**DE** `done:`, `loop:`, `skip:` duerfen in mehreren Routinen vorkommen; die spaeteren werden automatisch umbenannt (`done_2`), ihre Spruenge folgen.
**EN** `done:`, `loop:`, `skip:` may appear in several routines; the later ones are renamed (`done_2`) and their jumps follow.
## 3. Kommentare / comments
**DE** `{ ... }` und `(* ... *)` gehen im Asm-Block, auch ueber mehrere Zeilen und hinter einer Anweisung. So schaltet man Code mit Klammern ab, wie sonst in Pascal. `;` und `//` gehen weiter.
**EN** `{ ... }` and `(* ... *)` work in asm blocks, also over several lines and behind an instruction. Code can be switched off with braces like everywhere in Pascal. `;` and `//` still work.
## 4. Platzhalter: der Compiler waehlt die Register / placeholders: the compiler picks the registers
Code
var a, b, c : byte;
w, v : word;
l : longword;
...
asm in a, b out c; // a, b gelesen, c geschrieben
MOV %c, %a
ADD %c, %b
endasm;
asm inout w, v; // gelesen und geschrieben
ADIW %w, 1 // ADIW / SBIW: das Paar landet in R24 / R26
ADD %v, %w
ADC %v.1, %w.1 // %v.1 = zweites Byte
endasm;
| | |
|---|---|
| `in` | **DE** Variable wird vor dem Block in Register geladen / **EN** loaded into registers before the block |
| `out` | **DE** Register wird nach dem Block in die Variable gespeichert / **EN** stored back after the block |
| `inout` | **DE** beides / **EN** both |
| `%name` | **DE** erstes Byte (Low) / **EN** first byte (low) |
| `%name.1` .. `.3` | **DE** weitere Bytes / **EN** the next bytes |
**DE**
- Die Variablen sind Variablen einer Unit, lokale Variablen oder Parameter (by value) mit 1, 2 oder 4 Byte. Lokale Variablen liegen im Frame und werden mit `LDD` / `STD Rn, Y+q` geladen; VAR-Parameter gehen nicht (sie sind Zeiger).
- Felder eines Records: `rec.feld` (eine Ebene, global oder lokal); der Platzhalter heisst wie das Feld: `asm inout Counter.Tot;` ... `%Tot`.
- Konstanten gehen nur als `in`: kein Register, `%Name` ist der Wert, `%Name.0` .. `.3` seine Bytes (`LDI R20, %Limit.1`).
- `clobber R20, R21;` im Kopf nennt Register, die der Block sonst noch aendert (z.B. durch `MUL`, `LPM`); der Compiler vergibt sie nicht. Beispiel: `asm in a inout b clobber R20;`.
- Die Register kommen aus R16..R27 und sind immer obere Register: `LDI`, `CPI`, `SUBI`, `ANDI`, `ORI` gehen mit jedem Platzhalter. Register, die der Block selbst nennt (`R20`, `_ACCA`, `X` ...), vergibt der Compiler nicht.
- Mehrbyte-Werte liegen in aufeinanderfolgenden Registern. Ein Platzhalter, der bei `ADIW` / `SBIW` steht, bekommt R24 oder R26.
- Steht ein `CALL` im Block, warnt der Compiler: die gerufene Routine kann die Register aendern.
- Ist kein Register mehr frei, meldet der Compiler einen Fehler.
- Ein `%name`, das kein Platzhalter ist, bleibt unveraendert.
**EN**
- The variables are unit variables, local variables or parameters (by value) of 1, 2 or 4 bytes. Locals lie in the frame and are loaded with `LDD` / `STD Rn, Y+q`; VAR parameters do not work (they are pointers).
- Fields of a record: `rec.field` (one level, global or local); the placeholder is named like the field: `asm inout Counter.Tot;` ... `%Tot`.
- Constants only as `in`: no register, `%Name` is the value, `%Name.0` .. `.3` its bytes (`LDI R20, %Limit.1`).
- `clobber R20, R21;` in the header names registers the block changes besides the placeholders (e.g. by `MUL`, `LPM`); the compiler never gives them out. Example: `asm in a inout b clobber R20;`.
- The registers come from R16..R27 and are always upper registers, so `LDI`, `CPI`, `SUBI`, `ANDI`, `ORI` work with any placeholder. Registers the block names itself (`R20`, `_ACCA`, `X` ...) are never given out.
- Multi-byte values sit in consecutive registers. A placeholder used with `ADIW` / `SBIW` gets R24 or R26.
- A `CALL` in the block gives a warning: the called routine may change the registers.
- If no register is free the compiler reports an error.
- A `%name` that is not a placeholder stays as it is.
## 5. Pruefungen und Schutz / checks and protection
**DE**
- **Stack- und Frame-Bilanz:** fuer jeden Asm-Block folgt der Compiler allen Wegen (Spruenge, Skip-Befehle, Schleifen) und zaehlt `PUSH` / `POP` und den Frame (`ST -Y`, `LD Y+`, `ADIW` / `SBIW` auf Y). Bleibt auf einem Weg ein Rest, treffen sich zwei Wege mit verschiedenem Stand, oder wird SP / Frame-Zeiger direkt geschrieben, gibt es eine Warnung (auch ohne `{$W+}`). Ein Block direkt vor `return` / `exit` ist ein eigener Weg (vorzeitiger Ausstieg). Aus: Umgebungsvariable `AVRCO_NOASMCHECK=1`. Units aus dem System-Ordner und aus .PCU werden nicht geprueft.
- **Unbekanntes Compiler-Register** (`_ACCX`, Tippfehler): Fehler `unknown register _ACCX in the asm block` an der Zeile des Blocks. Der blanke Name `_ACC` bleibt erlaubt.
- **Outliner (Outline=1 / `-AO`):** Asm-Bloecke (auch die erzeugten von SoftSPI / SoftTWI / SoftUart), Interrupt-Routinen und `.PHASE`-Code bleiben unveraendert, ein Takt zaehlt dort. Eine unabhaengige Gegenpruefung verweigert jeden Helfer-Aufruf in einem Asm-Block.
- **Assembler:** `LOW(..)` / `HIGH(..)` werden vom Compiler umgesetzt (Abschnitt 1); mehr als 9 Fehler stoppen den Lauf, der Exit-Code ist 1.
**EN**
- **Stack and frame balance:** for every asm block the compiler follows all paths (jumps, skip instructions, loops) and counts `PUSH` / `POP` and the frame (`ST -Y`, `LD Y+`, `ADIW` / `SBIW` on Y). A warning (also without `{$W+}`) is given when a path leaves a rest, two paths meet with different counts, or SP / the frame pointer is written directly. A block right before `return` / `exit` is its own path (early exit). Off: environment variable `AVRCO_NOASMCHECK=1`. Units of the System folder and from .PCU are not checked.
- **Unknown compiler register** (`_ACCX`, a typo): error `unknown register _ACCX in the asm block` at the line of the block. The bare name `_ACC` stays valid.
- **Outliner (Outline=1 / `-AO`):** asm blocks (also the generated ones of SoftSPI / SoftTWI / SoftUart), interrupt routines and `.PHASE` code stay unchanged, the cycles count there. An independent cross-check refuses any helper call inside an asm block.
- **Assembler:** `LOW(..)` / `HIGH(..)` are translated by the compiler (section 1); more than 9 errors stop the run, exit code 1.
kommendes Demo: `Demos\AsmNames`, `Demos\AsmPlace`.
Steht aber alles bald im Online Handbuch hier.
miparo