83 lines
1.9 KiB
NASM
83 lines
1.9 KiB
NASM
.data
|
|
|
|
# Eingaben:
|
|
m: .long 3
|
|
n: .long 5
|
|
|
|
# Zu berechnen: x^n
|
|
|
|
intout: .string "Ergebnis: %d\n"
|
|
|
|
.text
|
|
######################################################################
|
|
.globl _main
|
|
.global _mainCRTStartup # debugging 4 msvs/windows
|
|
######################################################################
|
|
_mainCRTStartup: # do nothing
|
|
jmp _main # jump to _main
|
|
######################################################################
|
|
_main:
|
|
|
|
movl $0, %eax # Lade 0 in %eax
|
|
movl m, %ebx # Lade m in %ebx
|
|
movl n, %ecx # Lade n in %ecx
|
|
|
|
call .ackermann # call subrutine ackermann
|
|
|
|
jmp .end # finish
|
|
|
|
######################################################################
|
|
# %eax = current result
|
|
# %ebx = m
|
|
# %ecx = n
|
|
.ackermann:
|
|
|
|
cmp $0, %ebx # m = 0 ?
|
|
je .ackermann_ancor # jump to ancor
|
|
# m > 0
|
|
cmp $0, %ecx # n = 0 ?
|
|
je .ackermann_n_null_m_not_null # jump to n=0, m>0
|
|
# n > 0
|
|
jmp .ackermann_n_not_null_m_not_null # jump to n>0, m>0
|
|
|
|
.ackermann_n_null_m_not_null:
|
|
|
|
incl %ecx # n += 1 (n=1)
|
|
decl %ebx # m -= 1
|
|
call .ackermann # and call ackermann to calculate the rest
|
|
|
|
ret # outa here
|
|
|
|
.ackermann_n_not_null_m_not_null:
|
|
|
|
pushl %ebx # save m to stack
|
|
|
|
# A(m, n-1)
|
|
decl %ecx # n -= 1
|
|
call .ackermann # call ackermann to calculate A(m, n-1)
|
|
|
|
popl %ebx # get m back from stack
|
|
|
|
# A(m-1, A(m, n-1))
|
|
decl %ebx # m -= 1
|
|
movl %eax, %ecx # n = A(m, n-1)
|
|
call .ackermann # call ackermann to calculate the rest
|
|
|
|
ret # outa here
|
|
|
|
.ackermann_ancor: # ancor-marker
|
|
movl %ecx, %eax # result = n
|
|
incl %eax # result += 1
|
|
ret # jump out
|
|
|
|
######################################################################
|
|
.end:
|
|
# Wert im %eax ausgeben
|
|
pushl %eax
|
|
pushl $intout
|
|
call _printf
|
|
|
|
|
|
# Exit
|
|
movl $1, %eax
|
|
#int $0x80 |