IF condition in C translation to MIPS -
i want know why if(x == y)
in c programming language translated 'bne' condition , not 'beq' condition in mips ?
ignoring conditional moment, consider order in these blocks of code printed in assembler language instruction stream:
// if (x == y) { // b } // c
when
x == y
true, flow goes sequentially b c. there's no jump required on equality (beq
), because desired flow matches way blocks printed in instruction stream.when
x == y
false, @ end of flow has bypass b , jump straight c. that's why makes sense branch instruction triggered on inequality (bne
).
of course, take these example thought process particular case.
in general case, these implementation details. compiler may print instructions in way sees fit, including inverting conditionals. (keep in mind that, due modern cpu pipelines, strong optimization goal compiler guess execution path , ensure contains fewest possible jumps.)
Comments
Post a Comment