Files
riscv-emulator/beispielprogramme/8.txt
2025-07-09 22:42:51 +02:00

25 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#
# 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