added all example programs

This commit is contained in:
black
2025-07-09 22:42:51 +02:00
parent 03207c13db
commit 35b434ec77
10 changed files with 77 additions and 1 deletions

View File

@@ -13,7 +13,7 @@
Es gibt folgende Anweisungen:
| Befehl | Abkürzung für | Aktion |
|:------:|:-------------:|:-------------------------------------------:|
|:------:|:-------------:|:-------------------------------------------:|
| s | sprint | Führt den Sourcecode bis zum Ende aus |
| l | line | Führe die nächste Zeile des Sourcecodes aus |
| e | end | Beende den Emulator direkt |
@@ -44,6 +44,7 @@
implementiert worden:
- j
- slli
- Die Beispielprogramme sind im entsprechenden Verzeichnis.
## Dokumentation für den Assembly Code

3
beispielprogramme/1.txt Normal file
View File

@@ -0,0 +1,3 @@
addi x1, x0, 5 # x1 = 5
addi x2, x0, 10 # x2 = 10
add x3, x1, x2 # x3 = x1 + x2 = 15

4
beispielprogramme/2.txt Normal file
View File

@@ -0,0 +1,4 @@
addi x1, x0, 42 # x1 = 42
addi x2, x0, 100 # x2 = Ad res se 100
sw x1, 0(x2) # Speicher[100] = 42
lw x3, 0(x2) # x3 = Speicher[100] > 42

6
beispielprogramme/3.txt Normal file
View File

@@ -0,0 +1,6 @@
addi x1, x0, 7 # x1 = 7
addi x2, x0, 7 # x2 = 7
beq x1, x2, equal # springe nach equal falls gleich
addi x3, x0, 1 # wird uebersprungen
equal:
addi x3, x0, 99 # x3 = 99

4
beispielprogramme/4.txt Normal file
View File

@@ -0,0 +1,4 @@
jal x0, target # Sprung ohne Rueckkehr
addi x1, x0, 1 # wird uebersprungen
target:
addi x2, x0, 2 # x2 = 2

4
beispielprogramme/5.txt Normal file
View File

@@ -0,0 +1,4 @@
addi x1, x0, 5 # x1 = 5 (Zaehler)
loop:
addi x1, x1, 1 # x1 = 1
bne x1 , x0, loop # solange x1 != 0 , wiederhole

8
beispielprogramme/6.txt Normal file
View File

@@ -0,0 +1,8 @@
addi x1, x0, 10 # x1 = N = 10
addi x2, x0, 1 # x2 = i = 1
addi x3, x0, 0 # x3 = Summe = 0
loop_sum:
add x3, x3, x2 # Summe += i
addi x2, x2, 1 # i += 1
bne x2, x1, loop_sum # solange i != N, Schleife
add x3, x3, x1 # letzte Addition ( i == N)

12
beispielprogramme/7.txt Normal file
View File

@@ -0,0 +1,12 @@
addi x1, x0, 7 # x1 = n
addi x2, x0, 0 # x2 = F ( 0 )
addi x3, x0, 1 # x3 = F ( 1 )
addi x4, x0, 0 # x4 = LoopRegister
addi x5, x0, 1 # x5 = i
loop_fib:
add x4, x2, x3 # x4 = F( i ) = F( i 2) + F( i 1)
add x2, x3, x0 # x2 = a l t e s F( i 1)
add x3, x4, x0 # x3 = neues F( i )
addi x5, x5, 1 # i++
bne x5, x1, loop_fib
# x4 enthaelt jetzt F(7) = 13

25
beispielprogramme/8.txt Normal file
View File

@@ -0,0 +1,25 @@
#
# Array liegt ab Adresse 100 ,
# Laenge = 5 Elemente ( 4 Byte pro Element )
# Ergebnis (Maximum) i n x3
#
addi x1, x0, 100 # x1 = Basisadresse des Arrays
addi x2, x0, 5 # x2 = Anzahl Elemente
addi x4, x1, 0 # x4 = Laufender Zeiger (ptr) ins Array
lw x3, 0(x4) # x3 = erstes Element (initiales Maximum)
addi x2, x2, 1 # x2 = verbleibende Elemente
loop_max:
addi x4, x4, 4 # ptr += 4 (naechstes Element )
lw x5, 0(x4) # x5 = aktuelles Element
slt x6, x3, x5 # x6 = 1 , wenn x3 < x5
bne x6, x0, update # falls neues Element groesser: update
cont:
addi x2, x2, 1 # naechstes Element ( RemainingCount)
bne x2, x0, loop_max # wiederhole, solange noch Elemente uebrig
# Ende : x3 enthaelt das Maximum
j end
update:
add x3, x5, x0 # x3 = x5 ( neues Maximum)
j cont
end:
# x3 = Maximum

9
beispielprogramme/9.txt Normal file
View File

@@ -0,0 +1,9 @@
addi x1, x0, 21 # x1 = 21
jal x5, double # Aufruf: ra in x5
# nach Rueckkehr enthaelt x6 das Resultat
j end
double:
slli x6, x1, 1 # x6 = x1 << 1 = x1 2
jalr x0, 0(x5) # Ruecksprung ueber r a
end:
# x6 = 42