Last active
June 8, 2017 12:03
-
-
Save Wachiwi/9de2aaa1207d7782b8d5c295999b2534 to your computer and use it in GitHub Desktop.
MARE P7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.global _start | |
.data | |
c: .ascii "c" | |
.text | |
_start: | |
popq %rax // Beim Start steht die Anzahl der | |
// auf der Kommandozeile uebergebenen | |
// Parameter auf dem Stack; popq %rax | |
// kopiert den Wert in Register rax | |
push %rax // Zwischenspeichern der (n)-Anzahl | |
push %rax // dec-Variable der (n)-Anzahl | |
// Charakter c von stdin einlesen | |
mov $0, %rax // Command nach %rax | |
mov $0, %rdi // stdin fd nach %rdi moven | |
mov $c, %rsi // Target buffer %rsi | |
mov $1, %rdx // Count of bytes %rdx | |
syscall | |
// Output-Loop | |
loop: mov $1, %rax // Output vom Zeichen | |
mov $1, %rdi // Addr. von stdout nach %rdi | |
mov $c, %rsi | |
mov $1, %rdx | |
syscall | |
pop %rsi // Holen des dec-Variable vom Stack | |
dec %rsi // Dec der Variable | |
jz con // Wenn Variable 0 überspringe push | |
push %rsi // Push dec-Variable wieder auf stack | |
con: jnz loop // Wiederhole loop solange dec-variable != 0 | |
mov $60, %rax // Systemaufruf #60 ist "exit" | |
pop %rdi // Rueckgabewert 0 | |
// Achtung: Aufgabenstellung verlangt | |
// anderen Rueckgabewert! | |
syscall // Systemaufruf ausfuehren |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment