Mixed Language: C and Asm

This is a discussion on Mixed Language: C and Asm within the C Programming forums, part of the General Programming Boards category; oh, I had the idea of comparing it directly. But walking the string twice sucks Learnt another thing today. If ...

  1. #46
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    oh, I had the idea of comparing it directly. But walking the string twice sucks
    Learnt another thing today.
    If you push registers, then yes those values go on the stack at that appropriate place. You can do it before or after locals, it doesn't make a difference (as long as you get them off in the right order). (I believe it's customary for the registers to go first, though, as you have it.)
    Thanks tabstop and Anduril. Now, I can go to the exams without dreading some Assembly

    time to study some boring Databases. Ha, why is there no section on it? xD
    thanks guys.
    You ended that sentence with a preposition...Bastard!

  2. #47
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,498
    Did you fix your compare algorithm yet? Here is a little pseudo code if not:
    Code:
    cmpString:
        # regular function startup code
        # default eax to 0
    
    cmpLoop:
        # compare esi to edi and if they differ, exit the loop and go to stringsNotEqual
        # check string1 for a null.  we know the strings match up to this point
        #     so if one ends, they both end and we can safely jump to the exit label
        # increment esi and edi
        # jump back to the top of cmpLoop
    
    stringsNotEqual:
        # set eax to 1
    
    exit:
        # do all your regular exit code
    This way, we account for the length of different strings because the null in one string will compare not equal to whatever is in the other string, and we will exit the loop. We also avoid resetting eax to 1 then to 0 in every iteration of the loop.

  3. #48
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    I haven't fixed it yet. Thanks for the pseudocode.
    Yeah, I tried this method before. Not resetting %eax everytime but it wouldn't let me do it.
    I think i mentioned it earlier. It wouldn't let me use %eax in a label I called
    isEqual, there was always some random value in it. except for the function and exit.
    I will try it again and see what happens.
    You ended that sentence with a preposition...Bastard!

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21