This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Conditional jumps Assembly Vs C part01

Hello friends, In Assembly editor in KEIL (for 89LPC9xx series), things go easy. You make a jump point AT ANY LINE of main code(like point0:) and then you can conditionally jump back there to do something or reloop, according to program needs. Is there any chance you can do it with C ( ? ? ). Ofc there are (as i, a newbie knows) some looping statements like while() or for () - but in a specific application i am working these arent enough :(

I have the full flowing diagram of the code i need and i can email it to you just to see. If it was assembly it should be done by me and ready to release the project it in production line, but for C.... I am stuck for now...

Best regards all :)
Timothy Kondos

Parents
  • If you think you need a goto, these are the rules for its usage:

    #1 You are too stupid to use the language to implement the algorithm correctly.

    #2 If you still think you need a goto, make sure that somebody somewhere won't claim that you were "#1"

    #3 If you pass rule #2, then use it. Then document it so that another engineer, won't call you "#1" and attempt to re-write everything only to find out that you were not "#1" (If he succeeds in this re-write, then you were indeed "#1")

    #4 If you ignore these rules and think that 'goto' is a proper construct because it is intrinsic within the language's keywords such as 'for', 'switch', 'while', etc,... and "since it is used all the time in assembly", then you don't understand a major element and purpose of a higher-level programming language: the controlled use of 'goto' (then see rule #1)

    Also, when people talk about using 'goto' in deeply nested constructs, I still think that the code wasn't implemented correctly. The use of 'goto' becomes a lazy way to avoid the task of re-working your methods and algorithm (the deeply nested construct usually means that you've invested much effort into it to begin with, and dread the idea that you'll need to totally re-vamp 'all that code'). Just my opinion.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Reply
  • If you think you need a goto, these are the rules for its usage:

    #1 You are too stupid to use the language to implement the algorithm correctly.

    #2 If you still think you need a goto, make sure that somebody somewhere won't claim that you were "#1"

    #3 If you pass rule #2, then use it. Then document it so that another engineer, won't call you "#1" and attempt to re-write everything only to find out that you were not "#1" (If he succeeds in this re-write, then you were indeed "#1")

    #4 If you ignore these rules and think that 'goto' is a proper construct because it is intrinsic within the language's keywords such as 'for', 'switch', 'while', etc,... and "since it is used all the time in assembly", then you don't understand a major element and purpose of a higher-level programming language: the controlled use of 'goto' (then see rule #1)

    Also, when people talk about using 'goto' in deeply nested constructs, I still think that the code wasn't implemented correctly. The use of 'goto' becomes a lazy way to avoid the task of re-working your methods and algorithm (the deeply nested construct usually means that you've invested much effort into it to begin with, and dread the idea that you'll need to totally re-vamp 'all that code'). Just my opinion.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Children
  • #3 If you pass rule #2, then use it. Then document it so that another engineer, won't call you "#1" and attempt to re-write everything only to find out that you were not "#1" (If he succeeds in this re-write, then you were indeed "#1")
    I guess that for the last 15 years or so, for more than half my working time I have been coding in 'C'. I have yet to use a goto, simply because I have never found a reason to use it.

    Erik

  • The biggest reason for goto is people who wants to implement the full logic in a single function, just as they can (but should they?) implement the full in a single big block of assembler instructions.

    One problem with splitting an alorithm into multiple functions is how to share state information between the individual functions. But that is the reason why the world got object-oriented languages.

    The funny thing is that when a book describes the use of goto, the typical example is almost always trivially simple to rewrite to use the normal loop constructs. Just as all programming books has to take the factorial or Fibonacci series as examples of recursive functions, even if they are even simpler (and way more efficient) to implement as loops.