r/asm•
MJHApps

Any thoughts as to why the following nested loop takes so long?

I have a bare-bones nested loop which is taking far too long to execute and cannot figure out why. Any help would be greatly appreciated!

Here's just the outer loop. It takes 0.65ms to run on a 386:

                    xor    ecx, ecx
rayLoop:
                    push   ecx
                    pop    ecx
                    inc    ecx
                    cmp    ecx, 320                     
                    jne    rayLoop

However, when we add an inner loop, the whole shebang takes a whopping 48.6ms on the same machine:

                    xor     ecx, ecx
rayLoop:
                    push    ecx
                    mov     ecx, 200
rowLoop:             
                    dec     ecx
                    cmp     ecx, 50
                    jge     rowLoop
                    
                    pop     ecx
                    inc     ecx
                    cmp     ecx, 320                     
                    jne     rayLoop

What gives?

Posted Aug 17, 2017, 8:14 PM UTC

225
Loading comments…