66 lines
1.9 KiB
NASM
66 lines
1.9 KiB
NASM
########################################################################
|
|
.data
|
|
########################################################################
|
|
a: .long -10
|
|
b: .long 5
|
|
intout: .string "%d"
|
|
########################################################################
|
|
.text
|
|
########################################################################
|
|
.global _main # global entry point
|
|
.global _mainCRTStartup # debugging 4 msvs/windows
|
|
|
|
_mainCRTStartup: # do nothing
|
|
jmp _main # jump to _main
|
|
|
|
########################################################################
|
|
_main:
|
|
movl a, %eax # %eax = a
|
|
movl b, %ebx # %ebx = b
|
|
|
|
call mul_agy # rufe mul_agy auf
|
|
|
|
jmp _exit # jump to program-end
|
|
|
|
mul_agy:
|
|
|
|
cmp $0, %ebx # ist b = 0?
|
|
jz mul_agy_ancor # falls 0 springe zu mul_agy_ancor
|
|
|
|
movl %ebx, %ecx # kopiere b -> c
|
|
|
|
and $0b000001, %ecx # c = 0(gerade) / 1(ungerade)
|
|
cmp $0, %ecx # c = 0 ?
|
|
jz mul_agy_even # falls 0 springe zu mul_agy_even
|
|
|
|
mul_agy_uneven: # merke a, da b ungerade
|
|
pushl %eax # a auf den stack
|
|
|
|
sall $1, %eax # a<<1
|
|
shrl $1, %ebx # b>>>1
|
|
|
|
call mul_agy # rufe mul_agy auf
|
|
popl %ecx # hole a von stack und schreibe nach c
|
|
add %ecx, %eax # a = a + c
|
|
ret # springe in letzte rekursionsstufe
|
|
|
|
mul_agy_even: # ignoriere a, da b gerade
|
|
sall $1, %eax # a<<1
|
|
shrl $1, %ebx # b>>>1
|
|
call mul_agy # rufe mul_agy auf (oben wurde shcon geshiftet)
|
|
ret # springe in letzte rekursionsstufe
|
|
|
|
mul_agy_ancor:
|
|
xor %eax, %eax # %eax = 0;
|
|
ret # springe zurück
|
|
|
|
########################################################################
|
|
_exit: # global exit point
|
|
|
|
pushl %eax # nochmal eine ausgabe von eax
|
|
pushl $intout
|
|
call _printf
|
|
popl %ebx # clear stack
|
|
popl %eax # schreibe a in eax
|
|
|
|
ret |