• Log in or sign up for an account here: https://www.sythe.org/login

Struggling with x64 For Loops

Sypherz

Legend

$5 USD Donor New
Retired Sectional Moderator
Competition Winner
Joined
Dec 13, 2008
Sythe Gold
622
Messages
23,745
Sythe's 10th Anniversary
edit— figured it out. I think I was killing my loop in .L1 by comparing before calling sla.


I'm really struggling with an assignment right now-- hoping to get some advice from someone knowledgeable. I'm expecting this nested for loop to return 256, but in many cases it returns 0 for seemingly no reason. The lines with the exclamation marks cause my program to return 0 if not commented out, but I absolutely can't figure out why. I'm assembling with as and compiling with gcc.

Tyvm. @Sythe

Code:
#for loop from 0 to 256
fla:
    cmpq $256, %r10
    jl .L1
    movq %r10, %rax
    ret
.L1:
    addq $1,   %r10
    cmpq $256, %r10
    movq %r10, %rdi   #used to send value of r10 to nested for loop

    call sla
    jl .L1
    ret

#for loop from 8 to 0
sla:
    movq $8 , %r12
    cmpq $0 , %r12        !!!!!
    jne .L2               !!!!!
    ret
.L2:
    subq $1 , %r12
    cmpq $0 , %r12
    jne .L2
    ret
 
Last edited:
Heidy
Two Factor Authentication User
Hoover
Nitro Booster
Sythe's 15th Anniversary
As a tip: if you want to see how a compiler does something just throw your C++ code in here Compiler Explorer

+1 for this. Its really amazing for C++ optimizes some of the things.

constexpr for example
 
Runescape Gamblingrunescape gambling
Back
Top