IIm18-Kreativaufgabe7

Aus ProgrammingWiki

Wiki-Quelltext dieser Seite.

= Random Access Maschine  -  <tt>Paul Bachmann, Johannes Thies</tt> =

== RAM zur Ermittlung von $\left\lfloor \sqrt{n} \right\rfloor$==

Geben Sie mind. ein RAM-Programm zur Berechnung der Funktion $w : \N \mapsto \N$ mit $w(n) = \left\lfloor \sqrt{n} \right\rfloor$ an.

=== Ermittlung der Potenz ===

{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Befehlszähler
!Anweisung
!Bemerkung
|-
||<div align="right">0</div>||R0 = n|| belegen von R0 mit einer natürlichen Zahl n 
|-style="background-color:lightgrey;"
||<div align="right">1</div>||R1 = 1|| fixer Wert für Inkrementierung/Dekrementierung
|-
||<div align="right">2</div>||R2 = R0|| Festlegung einer Zählvariable der Größe n
|-style="background-color:lightgrey;"
||<div align="right">3</div>||R3 = 0|| R3 als Platzhalter für das Ergebnis
|-
||<div align="right">4</div>||R3 += R0|| Inkrementierung von R3 um n
|-style="background-color:lightgrey;"
||<div align="right">5</div>||R2 -= R1|| Dekrementierung der Zählvariable
|-
||<div align="right">6</div>||IFZERO R2 GOTO 8|| wenn Zählvariable 0 ist, dann steht das Ergebnis in R3
|-style="background-color:lightgrey;"
||<div align="right">7</div>||GOTO 4|| R1 von R0 subtrahieren
|-
||<div align="right">8</div>||R0 = R3|| Ergebnis in R0 speichern
|-style="background-color:lightgrey;"
||<div align="right">9</div>||STOP||
|}

=== Realisierung des logischen Operators $\leq$ ===

Kein RAM, sondern nur eine Visualisierung des Gedankenganges beim Vergleich zweier natürlicher Zahlen!

{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Befehlszähler
!Anweisung
!Bemerkung
|-
||<div align="right">0</div>||R0 = a|| belegen von R0 mit der ersten natürlichen Zahl a 
|-style="background-color:lightgrey;"
||<div align="right">1</div>||R1 = b|| belegen von R1 mit der ersten natürlichen Zahl b 
|-
||<div align="right">2</div>||R0 -= R1|| Dekrementierung von R0 um R1
|-style="background-color:lightgrey;"
||<div align="right">3</div>||IFZERO R0 GOTO ...|| Wenn R0 = 0, dann ist der Ursprüngliche Wert von R0 $\leq$ R1, wenn nicht, dann ist R0 > R1
|}

=== Kombination beider Funktionen zur Ermittlung von $\left\lfloor \sqrt{n} \right\rfloor$ ===

{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Befehlszähler
!Anweisung
!Bemerkung
|-
||<div align="right">0</div>||R0 = n|| belegen von R0 mit einer natürlichen Zahl n 
|-style="background-color:lightgrey;"
||<div align="right">1</div>||R1 = 1|| fixer Wert für Inkrementierung/Dekrementierung
|-
||<div align="right">2</div>||R2 += R1|| Zähler (Testvariable)
|-style="background-color:lightgrey;"
||<div align="right">3</div>||R22 = R2|| Potenz Zählvariable
|-
||<div align="right">4</div>||R33 += R2|| Inkrementierung von R3 um R2 zur Berechnung der Potenz von Testvariable
|-style="background-color:lightgrey;"
||<div align="right">5</div>||R22 -= R1|| Dekrementierung der Potenz Zählvariable
|-
||<div align="right">6</div>||IFZERO R22 GOTO 8|| wenn Zählvariable 0 ist, dann steht das Ergebnis in R33
|-style="background-color:lightgrey;"
||<div align="right">7</div>||GOTO 4|| Inkrementiere R33 solange bis Potenz Zählvariable 0 beträgt
|-
||<div align="right">8</div>||R33 -= R0|| kleinergelich Vergleich von Potenzergebnis und n
|-style="background-color:lightgrey;"
||<div align="right">9</div>||IFZERO R33 GOTO 2|| wenn R33 0 beträgt, dann ist Potenz von Testvariable $\leq$ n
|-
||<div align="right">10</div>||R2 -= R1|| Dekrementierung von R2 um 1, wenn Potenz der Testvariable zum ersten mal größer ist als n, da wir floor berechnen wollen
|-style="background-color:lightgrey;"
||<div align="right">11</div>||R0 = R2|| Ergebnis in R0 speichern
|}

=== Beispiel für n = 10 ===

{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Anweisung
!R0
!R1
!R1
!R22
!R33
|-
||R0 = n||10||0||0||0||0
|-style="background-color:lightgrey;"
||R1 = 1||10||1||0||0||0
|-
||R2 = R0||10||1||0||0||0
|-style="background-color:lightgrey;"
||R2 += R1||10||1||1||0||0
|-
||R22 = R2||10||1||1||1||0
|-style="background-color:lightgrey;"
||R33 += R2||10||1||1||1||1
|-
||R22 -= R1||10||1||1||0||1
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||10||1||1||0||1
|-
||R33 -= R0||10||1||1||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||10||1||1||0||0
|-
||R2 += R1||10||1||2||0||0
|-style="background-color:lightgrey;"
||R22 = R2||10||1||2||2||0
|-
||R33 += R2||10||1||2||2||2
|-style="background-color:lightgrey;"
||R22 -= R1||10||1||2||1||2
|-
||IFZERO R22 GOTO 10||10||1||2||1||2
|-style="background-color:lightgrey;"
||GOTO 6||10||1||2||1||2
|-
||R33 += R2||10||1||2||1||4
|-style="background-color:lightgrey;"
||R22 -= R1||10||1||2||0||4
|-
||IFZERO R22 GOTO 10||10||1||2||0||4
|-style="background-color:lightgrey;"
||R33 -= R0||10||1||2||0||0
|-
||IFZERO R22 GOTO 10||10||1||2||0||0
|-style="background-color:lightgrey;"
||R2 += R1||10||1||3||0||0
|-
||R22 = R2||10||1||3||3||0
|-style="background-color:lightgrey;"
||R33 += R2||10||1||3||3||3
|-
||R22 -= R1||10||1||3||2||3
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||10||1||3||2||3
|-
||GOTO 6||10||1||3||2||3
|-style="background-color:lightgrey;"
||R33 += R2||10||1||3||2||6
|-
||R22 -= R1||10||1||3||1||6
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||10||1||3||1||6
|-
||GOTO 6||10||1||3||1||6
|-style="background-color:lightgrey;"
||R33 += R2||10||1||3||1||9
|-
||R22 -= R1||10||1||3||0||9
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||10||1||3||0||9
|-
||R33 -= R0||10||1||3||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||10||1||3||0||0
|-
||R2 += R1||10||1||4||0||0
|-style="background-color:lightgrey;"
||R22 = R2||10||1||4||4||0
|-
||R33 += R2||10||1||4||4||4
|-style="background-color:lightgrey;"
||R22 -= R1||10||1||4||3||4
|-
||IFZERO R22 GOTO 10||10||1||4||3||4
|-style="background-color:lightgrey;"
||GOTO 6||10||1||4||3||4
|-
||R33 += R2||10||1||4||3||8
|-style="background-color:lightgrey;"
||R22 -= R1||10||1||4||2||8
|-
||IFZERO R22 GOTO 10||10||1||4||2||8
|-style="background-color:lightgrey;"
||GOTO 6||10||1||4||2||8
|-
||R33 += R2||10||1||4||2||12
|-style="background-color:lightgrey;"
||R22 -= R1||10||1||4||1||12
|-
||IFZERO R22 GOTO 10||10||1||4||1||12
|-style="background-color:lightgrey;"
||GOTO 6||10||1||4||1||12
|-
||R33 += R2||10||1||4||1||16
|-style="background-color:lightgrey;"
||R22 -= R1||10||1||4||0||16
|-
||IFZERO R22 GOTO 10||10||1||4||0||16
|-style="background-color:lightgrey;"
||R33 -= R0||10||1||4||0||6
|-
||IFZERO R22 GOTO 10||10||1||4||0||6
|-style="background-color:lightgrey;"
||R2 -= R1||10||1||3||0||6
|-
||R0 = R2||3||1||3||0||6
|-style="background-color:lightgrey;"
|}


=== Beispiel für n = 16 ===
{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Anweisung
!R0
!R1
!R1
!R22
!R33
|-
||R0 = n||16||0||0||0||0
|-style="background-color:lightgrey;"
||R1 = 1||16||1||0||0||0
|-
||R2 = R0||16||1||0||0||0
|-style="background-color:lightgrey;"
||R2 += R1||16||1||1||0||0
|-
||R22 = R2||16||1||1||1||0
|-style="background-color:lightgrey;"
||R33 += R2||16||1||1||1||1
|-
||R22 -= R1||16||1||1||0||1
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||1||0||1
|-
||R33 -= R0||16||1||1||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||1||0||0
|-
||R2 += R1||16||1||2||0||0
|-style="background-color:lightgrey;"
||R22 = R2||16||1||2||2||0
|-
||R33 += R2||16||1||2||2||2
|-style="background-color:lightgrey;"
||R22 -= R1||16||1||2||1||2
|-
||IFZERO R22 GOTO 10||16||1||2||1||2
|-style="background-color:lightgrey;"
||GOTO 6||16||1||2||1||2
|-
||R33 += R2||16||1||2||1||4
|-style="background-color:lightgrey;"
||R22 -= R1||16||1||2||0||4
|-
||IFZERO R22 GOTO 10||16||1||2||0||4
|-style="background-color:lightgrey;"
||R33 -= R0||16||1||2||0||0
|-
||IFZERO R22 GOTO 10||16||1||2||0||0
|-style="background-color:lightgrey;"
||R2 += R1||16||1||3||0||0
|-
||R22 = R2||16||1||3||3||0
|-style="background-color:lightgrey;"
||R33 += R2||16||1||3||3||3
|-
||R22 -= R1||16||1||3||2||3
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||3||2||3
|-
||GOTO 6||16||1||3||2||3
|-style="background-color:lightgrey;"
||R33 += R2||16||1||3||2||6
|-
||R22 -= R1||16||1||3||1||6
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||3||1||6
|-
||GOTO 6||16||1||3||1||6
|-style="background-color:lightgrey;"
||R33 += R2||16||1||3||1||9
|-
||R22 -= R1||16||1||3||0||9
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||3||0||9
|-
||R33 -= R0||16||1||3||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||3||0||0
|-
||R2 += R1||16||1||4||0||0
|-style="background-color:lightgrey;"
||R22 = R2||16||1||4||4||0
|-
||R33 += R2||16||1||4||4||4
|-style="background-color:lightgrey;"
||R22 -= R1||16||1||4||3||4
|-
||IFZERO R22 GOTO 10||16||1||4||3||4
|-style="background-color:lightgrey;"
||GOTO 6||16||1||4||3||4
|-
||R33 += R2||16||1||4||3||8
|-style="background-color:lightgrey;"
||R22 -= R1||16||1||4||2||8
|-
||IFZERO R22 GOTO 10||16||1||4||2||8
|-style="background-color:lightgrey;"
||GOTO 6||16||1||4||2||8
|-
||R33 += R2||16||1||4||2||12
|-style="background-color:lightgrey;"
||R22 -= R1||16||1||4||1||12
|-
||IFZERO R22 GOTO 10||16||1||4||1||12
|-style="background-color:lightgrey;"
||GOTO 6||16||1||4||1||12
|-
||R33 += R2||16||1||4||1||16
|-style="background-color:lightgrey;"
||R22 -= R1||16||1||4||0||16
|-
||IFZERO R22 GOTO 10||16||1||4||0||16
|-style="background-color:lightgrey;"
||R33 -= R0||16||1||4||0||0
|-
||IFZERO R22 GOTO 10||16||1||4||0||0
|-style="background-color:lightgrey;"
||R2 += R1||16||1||5||0||0
|-
||R22 = R2||16||1||5||5||0
|-style="background-color:lightgrey;"
||R33 += R2||16||1||5||5||5
|-
||R22 -= R1||16||1||5||4||5
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||5||4||5
|-
||GOTO 6||16||1||5||4||5
|-style="background-color:lightgrey;"
||R33 += R2||16||1||5||4||10
|-
||R22 -= R1||16||1||5||3||10
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||5||3||10
|-
||GOTO 6||16||1||5||3||10
|-style="background-color:lightgrey;"
||R33 += R2||16||1||5||3||15
|-
||R22 -= R1||16||1||5||2||15
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||5||2||15
|-
||GOTO 6||16||1||5||2||15
|-style="background-color:lightgrey;"
||R33 += R2||16||1||5||2||20
|-
||R22 -= R1||16||1||5||1||20
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||5||1||20
|-
||GOTO 6||16||1||5||1||20
|-style="background-color:lightgrey;"
||R33 += R2||16||1||5||1||25
|-
||R22 -= R1||16||1||5||0||25
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||5||0||25
|-
||R33 -= R0||16||1||5||0||9
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||16||1||5||0||9
|-
||R2 -= R1||16||1||4||0||9
|-style="background-color:lightgrey;"
||R0 = R2||4||1||4||0||9
|-
|}



=== Beispiel für n = 77 ===

{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Anweisung
!R0
!R1
!R1
!R22
!R33
|-
||R0 = n||77||0||0||0||0
|-style="background-color:lightgrey;"
||R1 = 1||77||1||0||0||0
|-
||R2 = R0||77||1||0||0||0
|-style="background-color:lightgrey;"
||R2 += R1||77||1||1||0||0
|-
||R22 = R2||77||1||1||1||0
|-style="background-color:lightgrey;"
||R33 += R2||77||1||1||1||1
|-
||R22 -= R1||77||1||1||0||1
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||1||0||1
|-
||R33 -= R0||77||1||1||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||1||0||0
|-
||R2 += R1||77||1||2||0||0
|-style="background-color:lightgrey;"
||R22 = R2||77||1||2||2||0
|-
||R33 += R2||77||1||2||2||2
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||2||1||2
|-
||IFZERO R22 GOTO 10||77||1||2||1||2
|-style="background-color:lightgrey;"
||GOTO 6||77||1||2||1||2
|-
||R33 += R2||77||1||2||1||4
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||2||0||4
|-
||IFZERO R22 GOTO 10||77||1||2||0||4
|-style="background-color:lightgrey;"
||R33 -= R0||77||1||2||0||0
|-
||IFZERO R22 GOTO 10||77||1||2||0||0
|-style="background-color:lightgrey;"
||R2 += R1||77||1||3||0||0
|-
||R22 = R2||77||1||3||3||0
|-style="background-color:lightgrey;"
||R33 += R2||77||1||3||3||3
|-
||R22 -= R1||77||1||3||2||3
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||3||2||3
|-
||GOTO 6||77||1||3||2||3
|-style="background-color:lightgrey;"
||R33 += R2||77||1||3||2||6
|-
||R22 -= R1||77||1||3||1||6
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||3||1||6
|-
||GOTO 6||77||1||3||1||6
|-style="background-color:lightgrey;"
||R33 += R2||77||1||3||1||9
|-
||R22 -= R1||77||1||3||0||9
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||3||0||9
|-
||R33 -= R0||77||1||3||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||3||0||0
|-
||R2 += R1||77||1||4||0||0
|-style="background-color:lightgrey;"
||R22 = R2||77||1||4||4||0
|-
||R33 += R2||77||1||4||4||4
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||4||3||4
|-
||IFZERO R22 GOTO 10||77||1||4||3||4
|-style="background-color:lightgrey;"
||GOTO 6||77||1||4||3||4
|-
||R33 += R2||77||1||4||3||8
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||4||2||8
|-
||IFZERO R22 GOTO 10||77||1||4||2||8
|-style="background-color:lightgrey;"
||GOTO 6||77||1||4||2||8
|-
||R33 += R2||77||1||4||2||12
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||4||1||12
|-
||IFZERO R22 GOTO 10||77||1||4||1||12
|-style="background-color:lightgrey;"
||GOTO 6||77||1||4||1||12
|-
||R33 += R2||77||1||4||1||16
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||4||0||16
|-
||IFZERO R22 GOTO 10||77||1||4||0||16
|-style="background-color:lightgrey;"
||R33 -= R0||77||1||4||0||0
|-
||IFZERO R22 GOTO 10||77||1||4||0||0
|-style="background-color:lightgrey;"
||R2 += R1||77||1||5||0||0
|-
||R22 = R2||77||1||5||5||0
|-style="background-color:lightgrey;"
||R33 += R2||77||1||5||5||5
|-
||R22 -= R1||77||1||5||4||5
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||5||4||5
|-
||GOTO 6||77||1||5||4||5
|-style="background-color:lightgrey;"
||R33 += R2||77||1||5||4||10
|-
||R22 -= R1||77||1||5||3||10
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||5||3||10
|-
||GOTO 6||77||1||5||3||10
|-style="background-color:lightgrey;"
||R33 += R2||77||1||5||3||15
|-
||R22 -= R1||77||1||5||2||15
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||5||2||15
|-
||GOTO 6||77||1||5||2||15
|-style="background-color:lightgrey;"
||R33 += R2||77||1||5||2||20
|-
||R22 -= R1||77||1||5||1||20
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||5||1||20
|-
||GOTO 6||77||1||5||1||20
|-style="background-color:lightgrey;"
||R33 += R2||77||1||5||1||25
|-
||R22 -= R1||77||1||5||0||25
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||5||0||25
|-
||R33 -= R0||77||1||5||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||5||0||0
|-
||R2 += R1||77||1||6||0||0
|-style="background-color:lightgrey;"
||R22 = R2||77||1||6||6||0
|-
||R33 += R2||77||1||6||6||6
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||6||5||6
|-
||IFZERO R22 GOTO 10||77||1||6||5||6
|-style="background-color:lightgrey;"
||GOTO 6||77||1||6||5||6
|-
||R33 += R2||77||1||6||5||12
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||6||4||12
|-
||IFZERO R22 GOTO 10||77||1||6||4||12
|-style="background-color:lightgrey;"
||GOTO 6||77||1||6||4||12
|-
||R33 += R2||77||1||6||4||18
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||6||3||18
|-
||IFZERO R22 GOTO 10||77||1||6||3||18
|-style="background-color:lightgrey;"
||GOTO 6||77||1||6||3||18
|-
||R33 += R2||77||1||6||3||24
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||6||2||24
|-
||IFZERO R22 GOTO 10||77||1||6||2||24
|-style="background-color:lightgrey;"
||GOTO 6||77||1||6||2||24
|-
||R33 += R2||77||1||6||2||30
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||6||1||30
|-
||IFZERO R22 GOTO 10||77||1||6||1||30
|-style="background-color:lightgrey;"
||GOTO 6||77||1||6||1||30
|-
||R33 += R2||77||1||6||1||36
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||6||0||36
|-
||IFZERO R22 GOTO 10||77||1||6||0||36
|-style="background-color:lightgrey;"
||R33 -= R0||77||1||6||0||0
|-
||IFZERO R22 GOTO 10||77||1||6||0||0
|-style="background-color:lightgrey;"
||R2 += R1||77||1||7||0||0
|-
||R22 = R2||77||1||7||7||0
|-style="background-color:lightgrey;"
||R33 += R2||77||1||7||7||7
|-
||R22 -= R1||77||1||7||6||7
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||6||7
|-
||GOTO 6||77||1||7||6||7
|-style="background-color:lightgrey;"
||R33 += R2||77||1||7||6||14
|-
||R22 -= R1||77||1||7||5||14
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||5||14
|-
||GOTO 6||77||1||7||5||14
|-style="background-color:lightgrey;"
||R33 += R2||77||1||7||5||21
|-
||R22 -= R1||77||1||7||4||21
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||4||21
|-
||GOTO 6||77||1||7||4||21
|-style="background-color:lightgrey;"
||R33 += R2||77||1||7||4||28
|-
||R22 -= R1||77||1||7||3||28
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||3||28
|-
||GOTO 6||77||1||7||3||28
|-style="background-color:lightgrey;"
||R33 += R2||77||1||7||3||35
|-
||R22 -= R1||77||1||7||2||35
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||2||35
|-
||GOTO 6||77||1||7||2||35
|-style="background-color:lightgrey;"
||R33 += R2||77||1||7||2||42
|-
||R22 -= R1||77||1||7||1||42
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||1||42
|-
||GOTO 6||77||1||7||1||42
|-style="background-color:lightgrey;"
||R33 += R2||77||1||7||1||49
|-
||R22 -= R1||77||1||7||0||49
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||0||49
|-
||R33 -= R0||77||1||7||0||0
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||7||0||0
|-
||R2 += R1||77||1||8||0||0
|-style="background-color:lightgrey;"
||R22 = R2||77||1||8||8||0
|-
||R33 += R2||77||1||8||8||8
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||7||8
|-
||IFZERO R22 GOTO 10||77||1||8||7||8
|-style="background-color:lightgrey;"
||GOTO 6||77||1||8||7||8
|-
||R33 += R2||77||1||8||7||16
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||6||16
|-
||IFZERO R22 GOTO 10||77||1||8||6||16
|-style="background-color:lightgrey;"
||GOTO 6||77||1||8||6||16
|-
||R33 += R2||77||1||8||6||24
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||5||24
|-
||IFZERO R22 GOTO 10||77||1||8||5||24
|-style="background-color:lightgrey;"
||GOTO 6||77||1||8||5||24
|-
||R33 += R2||77||1||8||5||32
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||4||32
|-
||IFZERO R22 GOTO 10||77||1||8||4||32
|-style="background-color:lightgrey;"
||GOTO 6||77||1||8||4||32
|-
||R33 += R2||77||1||8||4||40
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||3||40
|-
||IFZERO R22 GOTO 10||77||1||8||3||40
|-style="background-color:lightgrey;"
||GOTO 6||77||1||8||3||40
|-
||R33 += R2||77||1||8||3||48
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||2||48
|-
||IFZERO R22 GOTO 10||77||1||8||2||48
|-style="background-color:lightgrey;"
||GOTO 6||77||1||8||2||48
|-
||R33 += R2||77||1||8||2||56
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||1||56
|-
||IFZERO R22 GOTO 10||77||1||8||1||56
|-style="background-color:lightgrey;"
||GOTO 6||77||1||8||1||56
|-
||R33 += R2||77||1||8||1||64
|-style="background-color:lightgrey;"
||R22 -= R1||77||1||8||0||64
|-
||IFZERO R22 GOTO 10||77||1||8||0||64
|-style="background-color:lightgrey;"
||R33 -= R0||77||1||8||0||0
|-
||IFZERO R22 GOTO 10||77||1||8||0||0
|-style="background-color:lightgrey;"
||R2 += R1||77||1||9||0||0
|-
||R22 = R2||77||1||9||9||0
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||9||9
|-
||R22 -= R1||77||1||9||8||9
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||8||9
|-
||GOTO 6||77||1||9||8||9
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||8||18
|-
||R22 -= R1||77||1||9||7||18
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||7||18
|-
||GOTO 6||77||1||9||7||18
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||7||27
|-
||R22 -= R1||77||1||9||6||27
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||6||27
|-
||GOTO 6||77||1||9||6||27
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||6||36
|-
||R22 -= R1||77||1||9||5||36
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||5||36
|-
||GOTO 6||77||1||9||5||36
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||5||45
|-
||R22 -= R1||77||1||9||4||45
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||4||45
|-
||GOTO 6||77||1||9||4||45
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||4||54
|-
||R22 -= R1||77||1||9||3||54
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||3||54
|-
||GOTO 6||77||1||9||3||54
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||3||63
|-
||R22 -= R1||77||1||9||2||63
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||2||63
|-
||GOTO 6||77||1||9||2||63
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||2||72
|-
||R22 -= R1||77||1||9||1||72
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||1||72
|-
||GOTO 6||77||1||9||1||72
|-style="background-color:lightgrey;"
||R33 += R2||77||1||9||1||81
|-
||R22 -= R1||77||1||9||0||81
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||0||81
|-
||R33 -= R0||77||1||9||0||4
|-style="background-color:lightgrey;"
||IFZERO R22 GOTO 10||77||1||9||0||4
|-
||R2 -= R1||77||1||8||0||4
|-style="background-color:lightgrey;"
||R0 = R2||8||1||8||0||4
|-
|}

== RAM zur Ermittlung des größten gemeinsamen Teilers (ggt) - Euklidischer Algorithmus ==

{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Befehlszähler
!Anweisung
!Bemerkung
|-
||<div align="right">0</div>||R0 = a|| belegen von R0 mit der ersten natürlichen Zahl a 
|-style="background-color:lightgrey;"
||<div align="right">1</div>||R1 = b|| belegen von R1 mit der ersten natürlichen Zahl b 
|-
||<div align="right">2</div>||IFZERO R1 GOTO 12|| Sprung zu 12 da R0 das Ergebnis beinhaltet 
|-style="background-color:lightgrey;"
||<div align="right">3</div>||IFZERO R0 GOTO 11|| Sprung zu 11 da R1 das Ergebnis beinhaltet 
|-
||<div align="right">4</div>||R2 = R0|| Zwischenspeichern von R0 in R2 für Größer vergleich
|-style="background-color:lightgrey;"
||<div align="right">5</div>||R2 -= R1|| R1 von R2 subtrahieren für Größer vergleich
|-
||<div align="right">6</div>||IFZERO R2 GOTO 9|| wenn R2 0 ist, ist R1 > R0
|-style="background-color:lightgrey;"
||<div align="right">7</div>||R0 -= R1|| R1 von R0 subtrahieren
|-
||<div align="right">8</div>||GOTO 2|| Sprung zum Schleifenanfang
|-style="background-color:lightgrey;"
||<div align="right">9</div>||R1 -= R0|| R0 von R1 subtrahieren
|-
||<div align="right">10</div>||GOTO 2|| Sprung zum Schleifenanfang
|-style="background-color:lightgrey;"
||<div align="right">11</div>||R0 = R1|| Ergebnis in R0 schreiben
|-
||<div align="right">12</div>||STOP||
|}




=== Beispiel mit a = 2 und b = 4 ===
{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Anweisung
!R0
!R1
!R1
|-
||R0 = a ||2||0||0
|-style="background-color:lightgrey;"
||R1 = b ||2||4||0
|-
||IFZERO R1 GOTO 12 ||2||4||0
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||2||4||0
|-
||R2 = R0 ||2||4||2
|-style="background-color:lightgrey;"
||R2 -= R1 ||2||4||0
|-
||IFZERO R2 GOTO 11 ||2||4||0
|-style="background-color:lightgrey;"
||R1 -= R0 ||2||2||0
|-
||GOTO 2 ||2||2||0
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||2||2||0
|-
||IFZERO R0 GOTO 11||2||2||0
|-style="background-color:lightgrey;"
||R2 = R0 ||2||2||2
|-
||R2 -= R1 ||2||2||0
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||2||2||0
|-
||R1 -= R0 ||2||0||0
|-style="background-color:lightgrey;"
||GOTO 2 ||2||0||0
|-
||IFZERO R1 GOTO 12 ||2||0||0
|-style="background-color:lightgrey;"
|}




=== Beispiel mit a = 2 und b = 15 ===
{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Anweisung
!R0
!R1
!R1
|-
||R0 = a ||2||0||0
|-style="background-color:lightgrey;"
||R1 = b ||2||15||0
|-
||IFZERO R1 GOTO 12 ||2||15||0
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||2||15||0
|-
||R2 = R0 ||2||15||2
|-style="background-color:lightgrey;"
||R2 -= R1 ||2||15||0
|-
||IFZERO R2 GOTO 11 ||2||15||0
|-style="background-color:lightgrey;"
||R1 -= R0 ||2||13||0
|-
||GOTO 2 ||2||13||0
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||2||13||0
|-
||IFZERO R0 GOTO 11||2||13||0
|-style="background-color:lightgrey;"
||R2 = R0 ||2||13||2
|-
||R2 -= R1 ||2||13||0
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||2||13||0
|-
||R1 -= R0 ||2||11||0
|-style="background-color:lightgrey;"
||GOTO 2 ||2||11||0
|-
||IFZERO R1 GOTO 12 ||2||11||0
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||2||11||0
|-
||R2 = R0 ||2||11||2
|-style="background-color:lightgrey;"
||R2 -= R1 ||2||11||0
|-
||IFZERO R2 GOTO 11 ||2||11||0
|-style="background-color:lightgrey;"
||R1 -= R0 ||2||9||0
|-
||GOTO 2 ||2||9||0
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||2||9||0
|-
||IFZERO R0 GOTO 11||2||9||0
|-style="background-color:lightgrey;"
||R2 = R0 ||2||9||2
|-
||R2 -= R1 ||2||9||0
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||2||9||0
|-
||R1 -= R0 ||2||7||0
|-style="background-color:lightgrey;"
||GOTO 2 ||2||7||0
|-
||IFZERO R1 GOTO 12 ||2||7||0
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||2||7||0
|-
||R2 = R0 ||2||7||2
|-style="background-color:lightgrey;"
||R2 -= R1 ||2||7||0
|-
||IFZERO R2 GOTO 11 ||2||7||0
|-style="background-color:lightgrey;"
||R1 -= R0 ||2||5||0
|-
||GOTO 2 ||2||5||0
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||2||5||0
|-
||IFZERO R0 GOTO 11||2||5||0
|-style="background-color:lightgrey;"
||R2 = R0 ||2||5||2
|-
||R2 -= R1 ||2||5||0
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||2||5||0
|-
||R1 -= R0 ||2||3||0
|-style="background-color:lightgrey;"
||GOTO 2 ||2||3||0
|-
||IFZERO R1 GOTO 12 ||2||3||0
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||2||3||0
|-
||R2 = R0 ||2||3||2
|-style="background-color:lightgrey;"
||R2 -= R1 ||2||3||0
|-
||IFZERO R2 GOTO 11 ||2||3||0
|-style="background-color:lightgrey;"
||R1 -= R0 ||2||1||0
|-
||GOTO 2 ||2||1||0
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||2||1||0
|-
||IFZERO R0 GOTO 11||2||1||0
|-style="background-color:lightgrey;"
||R2 = R0 ||2||1||2
|-
||R2 -= R1 ||2||1||1
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||2||1||1
|-
||R0 -= R1 ||1||1||1
|-style="background-color:lightgrey;"
||GOTO 2 ||1||1||1
|-
||IFZERO R1 GOTO 12 ||1||1||1
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||1||1||1
|-
||R2 = R0 ||1||1||1
|-style="background-color:lightgrey;"
||R2 -= R1 ||1||1||0
|-
||IFZERO R2 GOTO 11 ||1||1||0
|-style="background-color:lightgrey;"
||R1 -= R0 ||1||0||0
|-
||GOTO 2 ||1||0||0
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||1||0||0
|-
|}




=== Beispiel mit a = 119 und b = 7 ===
{|| border="1" cellpadding="5" cellspacing="0"
|- style="text-align: center;background-color:lightgreen;"
!Anweisung
!R0
!R1
!R1
|-
||R0 = a ||119||0||0
|-style="background-color:lightgrey;"
||R1 = b ||119||7||0
|-
||IFZERO R1 GOTO 12 ||119||7||0
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||119||7||0
|-
||R2 = R0 ||119||7||119
|-style="background-color:lightgrey;"
||R2 -= R1 ||119||7||112
|-
||IFZERO R2 GOTO 11 ||119||7||112
|-style="background-color:lightgrey;"
||R0 -= R1 ||112||7||112
|-
||GOTO 2 ||112||7||112
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||112||7||112
|-
||IFZERO R0 GOTO 11||112||7||112
|-style="background-color:lightgrey;"
||R2 = R0 ||112||7||112
|-
||R2 -= R1 ||112||7||105
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||112||7||105
|-
||R0 -= R1 ||105||7||105
|-style="background-color:lightgrey;"
||GOTO 2 ||105||7||105
|-
||IFZERO R1 GOTO 12 ||105||7||105
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||105||7||105
|-
||R2 = R0 ||105||7||105
|-style="background-color:lightgrey;"
||R2 -= R1 ||105||7||98
|-
||IFZERO R2 GOTO 11 ||105||7||98
|-style="background-color:lightgrey;"
||R0 -= R1 ||98||7||98
|-
||GOTO 2 ||98||7||98
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||98||7||98
|-
||IFZERO R0 GOTO 11||98||7||98
|-style="background-color:lightgrey;"
||R2 = R0 ||98||7||98
|-
||R2 -= R1 ||98||7||91
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||98||7||91
|-
||R0 -= R1 ||91||7||91
|-style="background-color:lightgrey;"
||GOTO 2 ||91||7||91
|-
||IFZERO R1 GOTO 12 ||91||7||91
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||91||7||91
|-
||R2 = R0 ||91||7||91
|-style="background-color:lightgrey;"
||R2 -= R1 ||91||7||84
|-
||IFZERO R2 GOTO 11 ||91||7||84
|-style="background-color:lightgrey;"
||R0 -= R1 ||84||7||84
|-
||GOTO 2 ||84||7||84
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||84||7||84
|-
||IFZERO R0 GOTO 11||84||7||84
|-style="background-color:lightgrey;"
||R2 = R0 ||84||7||84
|-
||R2 -= R1 ||84||7||77
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||84||7||77
|-
||R0 -= R1 ||77||7||77
|-style="background-color:lightgrey;"
||GOTO 2 ||77||7||77
|-
||IFZERO R1 GOTO 12 ||77||7||77
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||77||7||77
|-
||R2 = R0 ||77||7||77
|-style="background-color:lightgrey;"
||R2 -= R1 ||77||7||70
|-
||IFZERO R2 GOTO 11 ||77||7||70
|-style="background-color:lightgrey;"
||R0 -= R1 ||70||7||70
|-
||GOTO 2 ||70||7||70
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||70||7||70
|-
||IFZERO R0 GOTO 11||70||7||70
|-style="background-color:lightgrey;"
||R2 = R0 ||70||7||70
|-
||R2 -= R1 ||70||7||63
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||70||7||63
|-
||R0 -= R1 ||63||7||63
|-style="background-color:lightgrey;"
||GOTO 2 ||63||7||63
|-
||IFZERO R1 GOTO 12 ||63||7||63
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||63||7||63
|-
||R2 = R0 ||63||7||63
|-style="background-color:lightgrey;"
||R2 -= R1 ||63||7||56
|-
||IFZERO R2 GOTO 11 ||63||7||56
|-style="background-color:lightgrey;"
||R0 -= R1 ||56||7||56
|-
||GOTO 2 ||56||7||56
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||56||7||56
|-
||IFZERO R0 GOTO 11||56||7||56
|-style="background-color:lightgrey;"
||R2 = R0 ||56||7||56
|-
||R2 -= R1 ||56||7||49
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||56||7||49
|-
||R0 -= R1 ||49||7||49
|-style="background-color:lightgrey;"
||GOTO 2 ||49||7||49
|-
||IFZERO R1 GOTO 12 ||49||7||49
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||49||7||49
|-
||R2 = R0 ||49||7||49
|-style="background-color:lightgrey;"
||R2 -= R1 ||49||7||42
|-
||IFZERO R2 GOTO 11 ||49||7||42
|-style="background-color:lightgrey;"
||R0 -= R1 ||42||7||42
|-
||GOTO 2 ||42||7||42
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||42||7||42
|-
||IFZERO R0 GOTO 11||42||7||42
|-style="background-color:lightgrey;"
||R2 = R0 ||42||7||42
|-
||R2 -= R1 ||42||7||35
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||42||7||35
|-
||R0 -= R1 ||35||7||35
|-style="background-color:lightgrey;"
||GOTO 2 ||35||7||35
|-
||IFZERO R1 GOTO 12 ||35||7||35
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||35||7||35
|-
||R2 = R0 ||35||7||35
|-style="background-color:lightgrey;"
||R2 -= R1 ||35||7||28
|-
||IFZERO R2 GOTO 11 ||35||7||28
|-style="background-color:lightgrey;"
||R0 -= R1 ||28||7||28
|-
||GOTO 2 ||28||7||28
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||28||7||28
|-
||IFZERO R0 GOTO 11||28||7||28
|-style="background-color:lightgrey;"
||R2 = R0 ||28||7||28
|-
||R2 -= R1 ||28||7||21
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||28||7||21
|-
||R0 -= R1 ||21||7||21
|-style="background-color:lightgrey;"
||GOTO 2 ||21||7||21
|-
||IFZERO R1 GOTO 12 ||21||7||21
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||21||7||21
|-
||R2 = R0 ||21||7||21
|-style="background-color:lightgrey;"
||R2 -= R1 ||21||7||14
|-
||IFZERO R2 GOTO 11 ||21||7||14
|-style="background-color:lightgrey;"
||R0 -= R1 ||14||7||14
|-
||GOTO 2 ||14||7||14
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||14||7||14
|-
||IFZERO R0 GOTO 11||14||7||14
|-style="background-color:lightgrey;"
||R2 = R0 ||14||7||14
|-
||R2 -= R1 ||14||7||7
|-style="background-color:lightgrey;"
||IFZERO R2 GOTO 11 ||14||7||7
|-
||R0 -= R1 ||7||7||7
|-style="background-color:lightgrey;"
||GOTO 2 ||7||7||7
|-
||IFZERO R1 GOTO 12 ||7||7||7
|-style="background-color:lightgrey;"
||IFZERO R0 GOTO 11||7||7||7
|-
||R2 = R0 ||7||7||7
|-style="background-color:lightgrey;"
||R2 -= R1 ||7||7||0
|-
||IFZERO R2 GOTO 11 ||7||7||0
|-style="background-color:lightgrey;"
||R1 -= R0 ||7||0||0
|-
||GOTO 2 ||7||0||0
|-style="background-color:lightgrey;"
||IFZERO R1 GOTO 12 ||7||0||0
|-
|}