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

Could you explain BCC command to me?

Hi,

I find C code not executing in the desired way. Then I step in assembly code of Tiva-C M4F core. Below is the disassembly code:

$C$L5:   nop

0000033a:   280A     CMP             R0, #10

0000033c:   D3C9     BCC             $C$L5

here_label:

R0 is '0'. It is found that after BCC exec, the core  goes $C$L5, not goes to here_label.

In xPSR, 'C' is '0'. I want to know BCC in detail, but the found description online is ambiguous to me. Especially the last column comments on Arithmetic. Could you explain the disassembly code running when flag 'C'=0, it goes to $C$L5, not here_label?


Thanks,

BCSC=1Carry setArithmetic operation gave carry out
BCCC=1Carry clearArithmetic operation did not produce a carry
Parents
  • Hello  ruwan2,
    according to ARMv7M ARMARM, the operation of

    "CMP<c><q> <Rn>, #<const>"

    is

    if ConditionPassed() then
    EncodingSpecificOperations();
    (result, carry, overflow) = AddWithCarry(R[n], NOT(imm32), '1');
    APSR.N = result<31>;
    APSR.Z = IsZeroBit(result);
    APSR.C = carry;
    APSR.V = overflow;

    In your case, the operation is
    0x00000000+0xFFFFFFF5+0x00000001=0xFFFFFFF6.
    This does not cause the carry.
    So BCC instruction is taken.

    In other words, the operation is "0-10 = -9",
    This causes not the carry but the borrow.
    The carry is complement (or inversion) of the borrow.
    So, if the borrow is '1', then the carry is '0'.

    Best regards,
    Yasuhiko Koumoto.

Reply
  • Hello  ruwan2,
    according to ARMv7M ARMARM, the operation of

    "CMP<c><q> <Rn>, #<const>"

    is

    if ConditionPassed() then
    EncodingSpecificOperations();
    (result, carry, overflow) = AddWithCarry(R[n], NOT(imm32), '1');
    APSR.N = result<31>;
    APSR.Z = IsZeroBit(result);
    APSR.C = carry;
    APSR.V = overflow;

    In your case, the operation is
    0x00000000+0xFFFFFFF5+0x00000001=0xFFFFFFF6.
    This does not cause the carry.
    So BCC instruction is taken.

    In other words, the operation is "0-10 = -9",
    This causes not the carry but the borrow.
    The carry is complement (or inversion) of the borrow.
    So, if the borrow is '1', then the carry is '0'.

    Best regards,
    Yasuhiko Koumoto.

Children