So, SUPER low-level what does an IF() look like, how is it handled by an x86 processor?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The processor has ‘Branch if’ instructions that when a certain condition is met it branches, and otherwise it continues on to the next instruction.
So
would become
More complex conditions (
if(A || B && C)) become a sequence of instructions that leaves a register in a 0 or non zero state, so the branchif instruction can jump or not jump based on the conditional flags.There are many conditional flags (zero, carry, negative, overflow, etc), and some branchif instructions also operate on more complex conditions (ie, it might actually check to see if a register is equal to another register, rather than simply looking at flags). Each architecture is different and makes tradeoffs so the instruction set is complete, but also speedy and compact.
As moocha points out in the comments, some architectures allow you to apply a conditional to some, many, or even all instructions, so you might not only have ‘branch if’ instructions, but also ‘and if’, ‘add if’, ‘move if’ etc.
The x86 is very, very, very complex beyond this simple explanation once you get into pipelining, out of order execution, caching, microcode, and all the other advanced topics. For most purposes the above explanation is sufficient. If you’re writing a hand crafted very, very tightly wound algorithm, though, you’ll have to take these things into account for maximum performance and throughput.
That’s a topic for another question though…
-Adam