# collatz fuer i386 UNIX # cc -o collatz collatz.s .set limit,10000 .text .globl main .type main,@function main: push %ebx mov $1,%ebx # ebx: i 0: mov %ebx,%ecx # ecx: j mov $-1,%edx # edx: k 1: inc %edx lea 1(%ecx,%ecx,2),%eax # eax = 3 * j + 1 shr %ecx # ecx = j /= 2; cmovc %eax,%ecx # j = j & 1 ? eax : ecx; jnz 1b # if (ecx != 0) goto 1; .section .rodata msg: .string "Fuer %d wurden %d Iterationen benoetigt.\n" .size msg,.-msg .text push %edx push %ebx push $msg call printf # printf(msg, i, k); add $12,%esp inc %ebx # i++ cmp $limit,%ebx jb 0b # if (i < sum) goto 0; xor %eax,%eax pop %ebx ret .size main,.-main