82 lines
1.0 KiB
NASM
82 lines
1.0 KiB
NASM
.data
|
|
## !!! GEHT IM MOMENT NUR BIS 2^30. Reicht das??
|
|
|
|
# Eingaben:
|
|
x: .long 2
|
|
n: .long 8
|
|
|
|
# Zu berechnen: x^n
|
|
|
|
|
|
intout:
|
|
.string "Wert: %d\n"
|
|
|
|
.text
|
|
|
|
.globl main
|
|
|
|
main:
|
|
|
|
|
|
movl x, %eax # Lade x in %eax
|
|
movl x, %ebx
|
|
|
|
|
|
movl n, %ecx # Lade n in %ecx
|
|
|
|
|
|
cmp $0, %ecx # n = 0 ?
|
|
je .n_0
|
|
jmp .loop_n
|
|
|
|
.n_0:
|
|
movl $1, %eax
|
|
jmp .end
|
|
|
|
|
|
.loop_n:
|
|
|
|
decl %ecx # n - 1
|
|
cmp $0, %ecx # n = 0 ? -> Dann fertig
|
|
je .end
|
|
|
|
call .iteration # Unterprogrammaufruf
|
|
|
|
|
|
|
|
jmp .loop_n
|
|
|
|
|
|
jmp .end
|
|
|
|
|
|
|
|
#Unterprogramm
|
|
|
|
## ICH ÜBERGEB HIER IMMER NUR %eax ICH WEISS NICHT OB DIE MEHR SEHN WOLLEN; ABER WAS SOLL MAN NOCH ÜBERGEBEN?
|
|
## WENN ICH DIE AUSKOMMENTIERTEN TEILE WIEDER REINMACHE GEHT IRGENDWIE NIX MEHR BEI MIR
|
|
|
|
|
|
.iteration:
|
|
pushl %ebp # alten Basepointer sichern
|
|
#movl %esp, %ebx # neuen Basepointer erzeugen
|
|
|
|
|
|
mull %ebx
|
|
|
|
popl %ebp # alten Basepointer wiederherstellen
|
|
#movl %ebp, %esp # Stackpointer zurücksetzen (alternativ mit "leave")
|
|
ret # return
|
|
|
|
|
|
.end:
|
|
|
|
# Wert im %eax ausgeben
|
|
pushl %eax
|
|
pushl $intout
|
|
call printf
|
|
|
|
|
|
# Exit
|
|
movl $1, %eax
|
|
int $0x80 |