Adblock breaks this site

Struggling with x64 For Loops

Discussion in 'Programming General' started by Sypherz, Nov 16, 2019.

  1. Sypherz

    Sypherz Legend
    $5 USD Donor New Retired Sectional Moderator Competition Winner

    Joined:
    Dec 13, 2008
    Posts:
    23,745
    Referrals:
    1
    Sythe Gold:
    622
    Discord Unique ID:
    1303476485860098070
    M
    Sythe's 10th Anniversary
    Struggling with x64 For Loops

    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: Nov 16, 2019
  2. Sythe

    Sythe Join our discord

    test

    Administrator Village Drunk

    Joined:
    Apr 21, 2005
    Posts:
    8,071
    Referrals:
    465
    Sythe Gold:
    5,271
    Discord Unique ID:
    742989175824842802
    Discord Username:
    Sythe
    Dolan Duck Dolan Trump Supporting Business ???
    Poképedia
    Clefairy Jigglypuff
    Who did this to my freakin' car!
    Hell yeah boooi
    Tier 3 Prizebox Toast Wallet User
    I'm LAAAAAAAME Rust Player Mewtwo Mew Live Free or Die Poké Prizebox (42) Dat Boi
    Struggling with x64 For Loops

    As a tip: if you want to see how a compiler does something just throw your C++ code in here Compiler Explorer
     
    Sypherz likes this.
  3. Zeus

    Zeus Discord Bot Developer
    $200 USD Donor New

    Joined:
    Mar 27, 2019
    Posts:
    1,287
    Referrals:
    3
    Sythe Gold:
    1,812
    Discord Unique ID:
    949810973512986654
    Discord Username:
    ronaldo_19
    Heidy Two Factor Authentication User Sythe's 15th Anniversary Nitro Booster (2) Hoover
    Struggling with x64 For Loops

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

    constexpr for example
     
    Sythe likes this.
< help a dude out | >


 
 
Adblock breaks this site