Topic
  • No replies
NealB
NealB
5 Posts

Pinned topic What, if any, machine code does the CONTINUE statement generate

‏2013-07-30T18:28:15Z |

The CONTINUE statement is commonly described as a being equivalent to a NOP in assembler. What exactly does a COBOL CONTNUE generate in terms of machine code? I am wondering if the compiler has the ability to optimize it right out of the program or does it always result in a machine instruction being executed?

I could compile a little program with the LIST option then review at the pseudo assembler that comes out, but is that totally accurate or are there situations where the CONTINUE can be completely optimized out of the program? For example, if CONTINUE were the last statement of a PERFORMed paragraph. 

 

 

Updated on 2013-07-30T18:29:20Z at 2013-07-30T18:29:20Z by NealB
  • BillWoodger
    BillWoodger
    137 Posts
    ACCEPTED ANSWER

    Re: What, if any, machine code does the CONTINUE statement generate

    ‏2013-07-31T23:13:13Z  

    CONTINUE, at no time and under no circumstance, generates any code.

    It will, often, "look" as though it has:

        IF A EQUAL TO B

            MOVE C TO D

            CONTINUE

        ELSE

            MOVE F TO D

        END-IF

     

    Here, the normal branch which will "jump over" the code for the MOVE F... will appear to be associated with the CONTINUE rather than with the MOVE C...

    Remove the CONTINUE and re-compile. The code generated will be 100% identical, on the LIST,NOFFSET output, the branch will now follow the MOVE C..., "seeming to be part of it".

    CONTINUE can be used deliberately as a "collection point" for compiler-generated code which is not strictly part of the preceding COBOL verb, but which is necessary for the program to work.

    This is similar to EXIT. EXIT generates no code. What does get "attached" to the EXIT on the LIST,NOOFFSET output is all the code for returning to where the PERFORM came from. Remove the EXIT and all that "returning code" then still appears, but now attached to the last COBOL verb encountered before the next paragraph/SECTION.

    In fact, although I'd not recommend it, CONTINUE and EXIT can be used entirely interchangeably. Neither, ever, uner any circumstance, generate any code. Add 1000 CONTNUEs and 1000 EXITs to a COBOL program, and the code geneated will be identical to the same program without any of those additional CONTINUEs or EXITs in it.

    CONTINUE generates no code. Ever. EXIT generates no code. Ever. I'm repeating it in an attempt to stay any gainsayers. Please, if you want to contradict, anyone, try it yourself first (despite what you already "know") and post the LIST,NOOFFSET output for the relevant code.

    Updated on 2013-07-31T23:15:39Z at 2013-07-31T23:15:39Z by BillWoodger
  • BillWoodger
    BillWoodger
    137 Posts

    Re: What, if any, machine code does the CONTINUE statement generate

    ‏2013-07-31T23:13:13Z  

    CONTINUE, at no time and under no circumstance, generates any code.

    It will, often, "look" as though it has:

        IF A EQUAL TO B

            MOVE C TO D

            CONTINUE

        ELSE

            MOVE F TO D

        END-IF

     

    Here, the normal branch which will "jump over" the code for the MOVE F... will appear to be associated with the CONTINUE rather than with the MOVE C...

    Remove the CONTINUE and re-compile. The code generated will be 100% identical, on the LIST,NOFFSET output, the branch will now follow the MOVE C..., "seeming to be part of it".

    CONTINUE can be used deliberately as a "collection point" for compiler-generated code which is not strictly part of the preceding COBOL verb, but which is necessary for the program to work.

    This is similar to EXIT. EXIT generates no code. What does get "attached" to the EXIT on the LIST,NOOFFSET output is all the code for returning to where the PERFORM came from. Remove the EXIT and all that "returning code" then still appears, but now attached to the last COBOL verb encountered before the next paragraph/SECTION.

    In fact, although I'd not recommend it, CONTINUE and EXIT can be used entirely interchangeably. Neither, ever, uner any circumstance, generate any code. Add 1000 CONTNUEs and 1000 EXITs to a COBOL program, and the code geneated will be identical to the same program without any of those additional CONTINUEs or EXITs in it.

    CONTINUE generates no code. Ever. EXIT generates no code. Ever. I'm repeating it in an attempt to stay any gainsayers. Please, if you want to contradict, anyone, try it yourself first (despite what you already "know") and post the LIST,NOOFFSET output for the relevant code.

    Updated on 2013-07-31T23:15:39Z at 2013-07-31T23:15:39Z by BillWoodger
  • NealB
    NealB
    5 Posts

    Re: What, if any, machine code does the CONTINUE statement generate

    ‏2013-08-01T13:37:10Z  

    CONTINUE, at no time and under no circumstance, generates any code.

    It will, often, "look" as though it has:

        IF A EQUAL TO B

            MOVE C TO D

            CONTINUE

        ELSE

            MOVE F TO D

        END-IF

     

    Here, the normal branch which will "jump over" the code for the MOVE F... will appear to be associated with the CONTINUE rather than with the MOVE C...

    Remove the CONTINUE and re-compile. The code generated will be 100% identical, on the LIST,NOFFSET output, the branch will now follow the MOVE C..., "seeming to be part of it".

    CONTINUE can be used deliberately as a "collection point" for compiler-generated code which is not strictly part of the preceding COBOL verb, but which is necessary for the program to work.

    This is similar to EXIT. EXIT generates no code. What does get "attached" to the EXIT on the LIST,NOOFFSET output is all the code for returning to where the PERFORM came from. Remove the EXIT and all that "returning code" then still appears, but now attached to the last COBOL verb encountered before the next paragraph/SECTION.

    In fact, although I'd not recommend it, CONTINUE and EXIT can be used entirely interchangeably. Neither, ever, uner any circumstance, generate any code. Add 1000 CONTNUEs and 1000 EXITs to a COBOL program, and the code geneated will be identical to the same program without any of those additional CONTINUEs or EXITs in it.

    CONTINUE generates no code. Ever. EXIT generates no code. Ever. I'm repeating it in an attempt to stay any gainsayers. Please, if you want to contradict, anyone, try it yourself first (despite what you already "know") and post the LIST,NOOFFSET output for the relevant code.

    Thankyou for your very complete and unambiguous answer. This is exactly what I was hoping to see :-)

  • BillWoodger
    BillWoodger
    137 Posts

    Re: What, if any, machine code does the CONTINUE statement generate

    ‏2013-08-02T00:10:12Z  
    • NealB
    • ‏2013-08-01T13:37:10Z

    Thankyou for your very complete and unambiguous answer. This is exactly what I was hoping to see :-)

    No problem.

    Sorry to anyone who feels I was a bit blunt, but I've been through this particular question on more than one occasion before, and, really, discussing, in-depth, COBOL code which generates no machine code is not especially interesting in itself.

    What makes it worse is that people do believe that CONTINUE (and EXIT) generate code. They don't go as far as producing examples to show that code is generated (that is they don't even try, rather than they try then realise it can't be done), they just assert that it is. Well, it isn't, no matter what anyone just "says", "thinks" or "believes".

    NealB, are your two questions related to each other? I was looking into processing the LIST output with the EXIT, then discovered that V5.1 has improvements to the LIST output, so put it off. If you are doing that, I have a small bug in the LIST output which won't come up often, but which you might like to know about. Contact me on LinkedIn if you want the details.