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

Regarding C program convert to disassembly

Hello,
I have written simple program for subtraction in keil by selecting the LPC2148 from NXP family. When i observe the disassembly window my subtraction c program convert to instruction SUB R2,R0,R1 which is not affecting the flags. If i want to convert disassembly in to SUBS R2,R0,R1 which thing i require to do. How compiler decide whether it has to use SUB or SUBS when it convert to disassembly?

  • You really should not care what instructions the compiler uses. That isn't part of the "contract" between you and the compiler.

    On the other hand, you can change the probability of the compiler doing things dependingo on your code constructs. If you have a statement:

    if ((b - a) < 0) { ... }
    


    Then the compiler can see a reason to care about the result being zero, above zero or below zero.

  • I am talking about flag set and reset. Means if a=b and c=a-b compiler convert this to SUB r0,r1,r2 so this instruction not affect the flag instead it can use SUBS instruction to change the flag status according to result.
    Here you are talking about execution of instruction acording to flag status. My question is change of flag status after execution.

  • Yes, but the compiler have no reason to care about setting any flags unless the compiler needs to perform a test based on the result of that subtraction. That was why my example showed an if statement.

    You really can't control what instructions the assembler ues. That is by definition the expected behavior of a compiler. When you pay someone to was your car, you can't expect to be able to request that the water should be splashed in clockwize instead of anti-clockwise circles. Such information isn't part of a deal when you pay for washing of a car.

    The compiler have means to show assembler output. But it doesn't need any means to control what sequence of instructions it should use. That is not any part of a relevant language standard.

    If you have a school teacher that expects you to hand in an assembler program, you can't force the compiler to generate a suitable sequence based on anything else than what is covered in the C/C++ standard regarding sequence points etc and analyzing side effects etc.

  • Please visit the Site contest.collectiva.in/.../ContestTraining.aspx To learn Fundamentals of C Programming online video tutorials in Tamil. It is very useful for the Beginners.