Grundlegende Befehle: Unterschied zwischen den Versionen
KKeine Bearbeitungszusammenfassung |
|||
| Zeile 4: | Zeile 4: | ||
=== Datenverarbeitungsbefehle === | === Datenverarbeitungsbefehle === | ||
''' | '''add''' (Addieren) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
add x0, x1, x2 ; x0 = x1 + x2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''sub''' (Subtrahieren) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
sub x0, x1, x2 ; x0 = x1 - x2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''mul''' (Multiplizieren) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
mul x0, x1, x2 ; x0 = x1 * x2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''div''' (Dividieren) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
udiv x0, x1, x2 ; x0 = x1 / x2 (unsigned) | |||
sdiv x0, x1, x2 ; x0 = x1 / x2 (signed) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Logische Befehle === | === Logische Befehle === | ||
''' | '''and''' (Bitweises UND) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
and x0, x1, x2 ; x0 = x1 & x2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''orr''' (Bitweises ODER) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
orr x0, x1, x2 ; x0 = x1 | x2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''eor''' (Exklusives ODER) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
eor x0, x1, x2 ; x0 = x1 ^ x2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''lsl''' (Logisches Schieben nach links) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
lsl x0, x1, #2 ; x0 = x1 << 2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''lsr''' (Logisches Schieben nach rechts) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
lsr x0, x1, #2 ; x0 = x1 >> 2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Speicherzugriffsbefehle === | === Speicherzugriffsbefehle === | ||
''' | '''ldr''' (Lade Register) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
ldr x0, [x1] ; Lade den Wert aus der Speicheradresse, die in x1 gespeichert ist, in x0 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''str''' (Speicher Register) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
str x0, [x1] ; Speichere den Wert aus x0 in die Speicheradresse, die in x1 gespeichert ist | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Bedingte Befehle === | === Bedingte Befehle === | ||
''' | '''b''' (Bedingungsloser Sprung) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
b label ; Springe zu einer bestimmten Marke (label) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''bl''' (Bedingungsloser Sprung mit Link) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
bl label ; Springe zu einer bestimmten Marke (label) und speichere die Rücksprungadresse | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''cbz''' (Vergleiche und springe, wenn null) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
cbz x0, label ; Springe zu einer bestimmten Marke (label), wenn x0 null ist | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''cbnz''' (Vergleiche und springe, wenn nicht null) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
cbnz x0, label ; Springe zu einer bestimmten Marke (label), wenn x0 nicht null ist | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Vergleichsbefehle === | === Vergleichsbefehle === | ||
''' | '''cmp''' (Vergleichen) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
cmp x0, x1 ; Vergleiche x0 und x1 und setze die Statusflags entsprechend | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''csel''' (Bedingte Auswahl) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
csel x0, x1, x2, EQ ; Wenn die Bedingung EQ (Equal) erfüllt ist, dann x0 = x1, sonst x0 = x2 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Spezielle Befehle === | === Spezielle Befehle === | ||
''' | '''nop''' (No Operation) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
nop ; Führt keine Operation aus, nützlich für Timing oder Platzhalter | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''brk''' (Breakpoint) | ||
<syntaxhighlight lang="asm"> | <syntaxhighlight lang="asm"> | ||
brk #0 ; Erzeugt eine Debugging-Breakpoint-Ausnahme | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Zeile 117: | Zeile 117: | ||
_start: | _start: | ||
ldr x1, =value1 ; Lade die Adresse von value1 in x1 | |||
ldr x2, [x1] ; Lade den Wert von value1 in x2 | |||
ldr x1, =value2 ; Lade die Adresse von value2 in x1 | |||
ldr x3, [x1] ; Lade den Wert von value2 in x3 | |||
add x4, x2, x3 ; Addiere die Werte und speichere das Ergebnis in x4 | |||
ldr x1, =result ; Lade die Adresse von result in x1 | |||
str x4, [x1] ; Speichere das Ergebnis in result | |||
brk #0 ; Beende das Programm | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Version vom 24. September 2024, 12:00 Uhr
Grundlegende Befehle für 64-BitAssembler
Assembler-Befehle (auch als Instruktionen oder Maschinenbefehle bezeichnet) für ARM-Prozessoren wie die ARM Cortex-A76 oder den Broadcom BCM2712 (der auf ARM-Technologie basiert) basieren auf der ARMv8-A Architektur. Hier sind einige grundlegende Befehle, die in der ARMv8-A Assembler-Programmierung verwendet werden:
Datenverarbeitungsbefehle
add (Addieren)
add x0, x1, x2 ; x0 = x1 + x2
sub (Subtrahieren)
sub x0, x1, x2 ; x0 = x1 - x2
mul (Multiplizieren)
mul x0, x1, x2 ; x0 = x1 * x2
div (Dividieren)
udiv x0, x1, x2 ; x0 = x1 / x2 (unsigned)
sdiv x0, x1, x2 ; x0 = x1 / x2 (signed)
Logische Befehle
and (Bitweises UND)
and x0, x1, x2 ; x0 = x1 & x2
orr (Bitweises ODER)
orr x0, x1, x2 ; x0 = x1 | x2
eor (Exklusives ODER)
eor x0, x1, x2 ; x0 = x1 ^ x2
lsl (Logisches Schieben nach links)
lsl x0, x1, #2 ; x0 = x1 << 2
lsr (Logisches Schieben nach rechts)
lsr x0, x1, #2 ; x0 = x1 >> 2
Speicherzugriffsbefehle
ldr (Lade Register)
ldr x0, [x1] ; Lade den Wert aus der Speicheradresse, die in x1 gespeichert ist, in x0
str (Speicher Register)
str x0, [x1] ; Speichere den Wert aus x0 in die Speicheradresse, die in x1 gespeichert ist
Bedingte Befehle
b (Bedingungsloser Sprung)
b label ; Springe zu einer bestimmten Marke (label)
bl (Bedingungsloser Sprung mit Link)
bl label ; Springe zu einer bestimmten Marke (label) und speichere die Rücksprungadresse
cbz (Vergleiche und springe, wenn null)
cbz x0, label ; Springe zu einer bestimmten Marke (label), wenn x0 null ist
cbnz (Vergleiche und springe, wenn nicht null)
cbnz x0, label ; Springe zu einer bestimmten Marke (label), wenn x0 nicht null ist
Vergleichsbefehle
cmp (Vergleichen)
cmp x0, x1 ; Vergleiche x0 und x1 und setze die Statusflags entsprechend
csel (Bedingte Auswahl)
csel x0, x1, x2, EQ ; Wenn die Bedingung EQ (Equal) erfüllt ist, dann x0 = x1, sonst x0 = x2
Spezielle Befehle
nop (No Operation)
nop ; Führt keine Operation aus, nützlich für Timing oder Platzhalter
brk (Breakpoint)
brk #0 ; Erzeugt eine Debugging-Breakpoint-Ausnahme
Beispielcode
Hier ist ein einfacher ARMv8-A Assembler-Programmcode, der zwei Zahlen addiert und das Ergebnis speichert:
.section .data
value1: .word 5
value2: .word 10
result: .word 0
.section .text
.global _start
_start:
ldr x1, =value1 ; Lade die Adresse von value1 in x1
ldr x2, [x1] ; Lade den Wert von value1 in x2
ldr x1, =value2 ; Lade die Adresse von value2 in x1
ldr x3, [x1] ; Lade den Wert von value2 in x3
add x4, x2, x3 ; Addiere die Werte und speichere das Ergebnis in x4
ldr x1, =result ; Lade die Adresse von result in x1
str x4, [x1] ; Speichere das Ergebnis in result
brk #0 ; Beende das Programm