college/ws2010/gdi3/p1/A2.2.asm.txt
2011-10-18 10:28:57 +02:00

44 lines
708 B
Plaintext

.data
a = 15
b = 3
start:
push 0x0FFFFF #stackmarker
movl $a, %eax # eax = a
movl $b, %ebx # ebx = b
mul_agy:
if(%ebx == 0) #anker
jmp sum_stack #sum and print
movl %ebx, %ecx # copy current b
and 0x000001 %ecx # %ecx = 0(gerade) / 1(ungerade)
if(%ecx == 1) # falls ungerade (use flags)
push %eax # stack a
shll $1, %eax # a << 1
shrl $1, %ebx # b >> 1
jmp agy
sum_stack:
pop %eax
xor %edx, %edx # 0
movl %eax, %ebx
and 0x0FFFFF, %ebx
if(%ebx != 0x0FFFFF)
add %eax, %edx
jmp sum_stack
movl %edx, %eax #write back
#Anmerkung: Es geht auch in einer Funktion via Rekursion, allerdings hab ich das noch nicht überlegt. Dann ist kein stack marker mehr notwendig