Struggling with x64 For Loops

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

Struggling with x64 For Loops
  1. Unread #1 - Nov 16, 2019 at 9:24 PM
  2. Sypherz
    Joined:
    Dec 13, 2008
    Posts:
    23,745
    Referrals:
    1
    Sythe Gold:
    622
    M
    Sythe's 10th Anniversary

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

    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
  3. Unread #2 - Nov 17, 2019 at 6:58 AM
  4. Sythe
    Joined:
    Apr 21, 2005
    Posts:
    8,063
    Referrals:
    450
    Sythe Gold:
    5,191
    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

    Sythe Join our discord

    test

    Administrator Village Drunk

    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.
  5. Unread #3 - Nov 18, 2019 at 1:32 PM
  6. Zeus
    Joined:
    Mar 27, 2019
    Posts:
    1,279
    Referrals:
    3
    Sythe Gold:
    1,804
    Discord Unique ID:
    295410796370984970
    Discord Username:
    ZeusS#5241
    Heidy Two Factor Authentication User Sythe's 15th Anniversary Nitro Booster (2) Hoover

    Zeus Discord Bot Developer
    $200 USD Donor New

    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 | >

Users viewing this thread
1 guest


 
 
Adblock breaks this site