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

Using C and reading CPU Register (Carry-Flag) via assembler

Hi smart guys out there,

I am using µVision with TIs eval-kit LM3S9B92. I use µVisions C-Compiler.

I learned that it is not possible to read the CPU-Registers with C and I have to use asembler for that.

I have no idea of asembler and actually I don't work with it in future and I hope I never have to again :-) ...but right now I need to know the status of the carrybit.

So all I am asking is for a piece of code that gets me the status of bit 29 in the register 17 :) and how to implement that in my project.

I hope this doesn't sound sassy ;-) - at least it isn't meant that way.

Thank you so much.

Parents
  • The ARM compiler is "smart" enough that it merges the assembler instructions with the instructions generated from the C code. Then it performs a number of optimization steps.

    So inlined assembler need not survive unmodified to the finaly binary.

    If you want to implement a large-number library while using the carry flag, then you should implement the evaluations fully in assembler.

    Note that a comparison "if (a >= b)" is very fast on the ARM processor, and the optimizer will recognize that it's the same variables in the comparison as in the actual subtraction. So no extra memory accesses. Just a comparison. And the optimizer might even note that the comparison and the subtraction are basically the same thing, and the code is still interested in a subtraction.

    When programming in C - do stay with C. Do not try to fool the optimizer by taking short cuts. When you are not happy with C, because of special needs: write full functions in assembler.

Reply
  • The ARM compiler is "smart" enough that it merges the assembler instructions with the instructions generated from the C code. Then it performs a number of optimization steps.

    So inlined assembler need not survive unmodified to the finaly binary.

    If you want to implement a large-number library while using the carry flag, then you should implement the evaluations fully in assembler.

    Note that a comparison "if (a >= b)" is very fast on the ARM processor, and the optimizer will recognize that it's the same variables in the comparison as in the actual subtraction. So no extra memory accesses. Just a comparison. And the optimizer might even note that the comparison and the subtraction are basically the same thing, and the code is still interested in a subtraction.

    When programming in C - do stay with C. Do not try to fool the optimizer by taking short cuts. When you are not happy with C, because of special needs: write full functions in assembler.

Children