IFs in a CPU?
| .NET Framework/non-language specific Discuss, IFs in a CPU? at Programmers Lounge forum; Ths has bothered me for a while, how does a CPU make a decision? It's essentially pumping a string of ... |
| Notices | Welcome to the Gamerz Needs forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |  | 
08-03-2008, 05:18 AM
|  | Gold Double Sided Axe+ | | | Last Online: Yesterday 07:19 PM Join Date: Oct 2006 Location: As far away from you as possible
Posts: 276
Thanks: 20
Thanked 42 Times in 23 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 5 Points: 3,422.27 Bank: 0.00 Total Points: 3,422.27 | | | IFs in a CPU?
Ths has bothered me for a while, how does a CPU make a decision? It's essentially pumping a string of electrons, so how does that work on an IF statement? My only thinking could be you evaluate the condition, multiply the result by 64 or something, and then jump to [current address+(condition*0x40)], because then it would jump ahead 64 on TRUE, and jump ahead 0 on FALSE.. but that doesn't sound right. Oh and yes, this is an ASM representation vs a CPU representation.
How does a computer evaluate a conditional?
__________________
Programmer in C++ and webpage stuff.. some C# and Java applets, and some DirectX & OpenGL.
My display pic is from http://www.homestarrunner.com | 
09-24-2008, 11:20 AM
| | X-Staff | | | Last Online: 11-16-2008 03:35 AM Join Date: Jun 2006 Location: England
Posts: 4,729
Thanks: 185
Thanked 1,186 Times in 638 Posts
Nominated 2 Times in 1 Post TOTW/F/M Award(s): 0
Latest Blog: Exam Results
Rep Power: 23 Points: 937.30 Bank: 161,489.27 Total Points: 162,426.57 | | | Old thread but has no reply yet..
A computer evaluates conditions essentially by comparing and if equal, it sets a flag in the EFLAGs register named the zero flag. There are then JMPs that are conditional on the state of various flags.
So in an IF statement, the condition is evaluated and the code execution jumps conditionally as a result of the comparison.
Is that what you wanted to know ? | 
09-24-2008, 12:31 PM
|  | Gold Double Sided Axe+ | | | Last Online: Yesterday 07:19 PM Join Date: Oct 2006 Location: As far away from you as possible
Posts: 276
Thanks: 20
Thanked 42 Times in 23 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 5 Points: 3,422.27 Bank: 0.00 Total Points: 3,422.27 | | |
yes it is, but since then I've figured it out.. I was actually looking for a much lower-level explanation though. I understand conditional jumps, but what I wanted to know was how it evaluates the condition. Either way, it's all just boolean logic (greater than, less than, greater than or equal, etc.).. they can all be evaluated with the right boolean function. I understand it. Thanks though
__________________
Programmer in C++ and webpage stuff.. some C# and Java applets, and some DirectX & OpenGL.
My display pic is from http://www.homestarrunner.com | 
09-25-2008, 02:12 AM
| | X-Staff | | | Last Online: 11-16-2008 03:35 AM Join Date: Jun 2006 Location: England
Posts: 4,729
Thanks: 185
Thanked 1,186 Times in 638 Posts
Nominated 2 Times in 1 Post TOTW/F/M Award(s): 0
Latest Blog: Exam Results
Rep Power: 23 Points: 937.30 Bank: 161,489.27 Total Points: 162,426.57 | | | At a hardware level, it's just logic gates. For example, to compare a 1 and a 0 state, they could put it through a OR gate and if the result is one then that could clear the zero flag. I am speculating about the exact gate they use but OR would certainly work for comparing 1 and 0. | 
09-25-2008, 03:52 AM
|  | Gold Double Sided Axe+ | | | Last Online: Yesterday 07:19 PM Join Date: Oct 2006 Location: As far away from you as possible
Posts: 276
Thanks: 20
Thanked 42 Times in 23 Posts
Nominated 0 Times in 0 Posts TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 5 Points: 3,422.27 Bank: 0.00 Total Points: 3,422.27 | | |
yeah I know. again, I figured it out. For those still wondering, reading the Art of Assembly really helps. Thanks though
__________________
Programmer in C++ and webpage stuff.. some C# and Java applets, and some DirectX & OpenGL.
My display pic is from http://www.homestarrunner.com |  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | |