Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
| gf_informatik:assembler_sca [2022-06-29 06:40] – [Aufgabe 2] sca | gf_informatik:assembler_sca [2023-08-01 15:35] (aktuell) – [Instruction Set] sca | ||
|---|---|---|---|
| Zeile 13: | Zeile 13: | ||
| - | ==== Instruction Set ==== | ||
| - | |||
| - | ^ Code ^ Name ^ Description ^ | ||
| - | | 0 | HLT | Stop (Little Man has a rest). | | ||
| - | | 1 | ADD | Add the contents of the memory address to the Accumulator | | ||
| - | | 2 | SUB | Subtract the contents of the memory address from the Accumulator | | ||
| - | | 3 | STA or STO | Store the value in the Accumulator in the memory address given. | | ||
| - | | 4 | | This code is unused and gives an error. | | ||
| - | | 5 | LDA | Load the Accumulator with the contents of the memory address given | | ||
| - | | 6 | BRA | Branch - use the address given as the address of the next instruction | | ||
| - | | 7 | BRZ | Branch to the address given if the Accumulator is zero | | ||
| - | | 8 | BRP | Branch to the address given if the Accumulator is zero or positive | | ||
| - | | 9 | INP or OUT | Input or Output. Take from Input if address is 1, copy to Output if address is 2. | | ||
| - | | 9 | OTC | Output accumulator as a character if address is 22. (Non-standard instruction) | | ||
| - | | 9 | DAT | Used to indicate a location that contains data.| | ||
| ===== Aufgaben ===== | ===== Aufgaben ===== | ||
| Zeile 51: | Zeile 36: | ||
| 1. Schreibe den Code so um, dass nun **vier Zahlen addiert** werden können. | 1. Schreibe den Code so um, dass nun **vier Zahlen addiert** werden können. | ||
| - | ==== Aufgabe 2 ==== | + | ==== Aufgabe 2: Schleifen |
| - | Nun wollen wir ein einfaches | + | Nun wollen wir **Schleifen** (ähnlich wie *while* in Python) |
| <code asm> | <code asm> | ||
| ... | ... | ||
| - | BRP JMP // if accumulator is zero or positive, jump to line marked with JMP | + | LOOP ... // here loop starts |
| ... | ... | ||
| - | JMP ... | + | BRP LOOP // if accumulator is >= 0, jump to LOOP (can also use different name) |
| ... | ... | ||
| </ | </ | ||
| - | 1. Studiere im Manual die Befehle | + | 1. Studiere im Manual die **Sprung-Instruktionen** |
| - | 1. Schreibe | + | 1. Schreibe Assembler-Code, der einen **Countdown** ausführt (siehe unten): |
| - | ==== Aufgabe 3 ==== | + | 1. eine Zahl wird eingelesen |
| + | 1. wiederholen, | ||
| + | 1. die Zahl wird ausgeben | ||
| + | 1. die Zahl wird um 1 verringert | ||
| - | Schreibe Assembler-Code, | + | **Hinweise:** |
| - | * eine Zahl wird eingelesen | + | * Mit `ONE DAT 1` kann nach dem eigentlichen Programm |
| - | * wiederholen, solange | + | * Welche **Sprung-Instruktion** musst du hier verwenden? |
| - | * die Zahl wird ausgeben | + | |
| - | * die Zahl wird um 1 verringert | + | |
| - | Hinweise: | + | < |
| - | * mit `DAT 1` kann nach dem eigentlichen Programm eine Zahl (z.B. $1$) in den Speicher geschrieben werden, die dann für die Subtraktion verwendet werden kann. | + | |
| - | * die Wiederholung benötigt eine Sprung-Instruktion (Branch, Instruktionen 6-8) - welcher ist der richtige? | + | |
| - | + | ||
| - | < | + | |
| ++++Lösung: | ++++Lösung: | ||
| <code asm> | <code asm> | ||
| Zeile 90: | Zeile 72: | ||
| </ | </ | ||
| - | ==== Aufgaben | + | ==== Aufgabe 3: Verzweigungen ==== |
| + | |||
| + | Nun wollen wir einfache **Verzweigungen** (entspricht **if-else**-Statement in Python) in Assembler programmieren. Bei einem solchen wird eine *Bedingung* überprüft. Je nachdem, ob diese erfüllt ist, *springt* der Code dann an eine andere Stelle. Dazu verwendet man, ganz ähnlich wie bei Schleifen, die **Sprung-Instruktionen**. Der Unterschied hier ist, dass man nicht zurück sondern nach weiter unten im Code springt. | ||
| + | |||
| + | <code asm> | ||
| + | ... | ||
| + | BRP JMP // if accumulator is zero or positive, jump to line marked with JMP | ||
| + | ... | ||
| + | JMP ... | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | 1. Studiere im Manual die Befehle BRA, BRZ, BRP | ||
| + | 1. Schreibe ein Assembler-Programm, | ||
| + | |||
| + | |||
| + | <nodisp 2> | ||
| + | ++++Lösung: | ||
| + | <code asm> | ||
| + | </ | ||
| + | ++++ | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Aufgaben | ||
| Löse eine der folgenden Aufgaben; verwende Labels und Branching Instructions. | Löse eine der folgenden Aufgaben; verwende Labels und Branching Instructions. | ||