c - Assembler generates negative forms of conditions, not positive one -


i wondered why gcc assembler use negative form of conditions instead of positive one. suppose have following c code:

if (x == 10) {   x ++; }  y ++; 

when use gcc compile , produce object file, result of assembly code in powerpc assembly follows:

  20:   2c 00 00 0a     cmpwi   r0,10   24:   40 82 00 10     bne 34 <main+0x34>   28:   81 3f 00 08     lwz r9,8(r31)   2c:   38 09 00 01     addi    r0,r9,1   30:   90 1f 00 08     stw r0,8(r31)   34:   81 3f 00 0c     lwz r9,12(r31)   38:   38 09 00 01     addi    r0,r9,1   3c:   90 1f 00 0c     stw r0,12(r31) 

the assembly uses bne while used equal == in c code.

edit 1:

i know code working perfectly. means why assembler use negative form not positive one.

edit 2: using compiler level 0 optimizer , know that, not intelligent. means question that, why assembler couldn't produce assembly such below:

cmpi x, 10 beq label1 b label2  label1: add x, x, 1 label2: add y, y, 1 

could 1 please explain happens?

thanks in advance.

the reason the negative form simple : branching opposite of if. branching means "skip if", while if means "execute if". so, assembly conditional branching model, if conditions negated translate single branch. if+else, doesn't matter because 2 can swapped, negation preserved.

negating intuitive thing here ; take example :

if (x == 10) {     x++; } y++; 

when "run" code in head, do ? @ condition, , check if true. if is, x++, y++. if isn't, jump directly y++. in other words, jump (branch) y++ if condition false ; intuitively negate condition.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -