element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum Digital logic gates
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 2 replies
  • Answers 2 answers
  • Subscribers 276 subscribers
  • Views 473 views
  • Users 0 members are here
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

Digital logic gates

mihinduep
mihinduep over 5 years ago

I think it a waste of the resources of a micro-processor to have the IF logic gate. When you are programming and doing a loop in a program, you put a counter x and check IF x is eaqual to one in the first round of the loop and do a certain task IF x is eaqual to one. Or else perform a different task if x is greater than one in the next loop which would mean x is eaqual to two. What I am trying to say is, x would definitely be eaqual to one in the first round of the loop. So why not check WHEN x eaqual to one in the first round of the loop than IF x is eaqual to one. Can't this IF gate be taken out of computer logic gates altogether and replace it with the WHEN gate?

  • Sign in to reply
  • Cancel

Top Replies

  • Gough Lui
    Gough Lui over 5 years ago +3 suggested
    What you are talking about are not gates. The hardware doesn't work that way. Look up the instruction set for your processor and you will realise that most processors are only able to do a limited number…
  • phoenixcomm
    phoenixcomm over 5 years ago in reply to Gough Lui +2 suggested
    Gough Lui No, it's not really the program code that is doing the heavy lifting here. All CPUs have what is known as the instruction set which is in machine code. This controls the gates etc, via microcode…
  • Gough Lui
    0 Gough Lui over 5 years ago

    What you are talking about are not gates. The hardware doesn't work that way. Look up the instruction set for your processor and you will realise that most processors are only able to do a limited number of conditional things - i.e. test for equality, branch if equal or not equal, etc. There is no such thing as an IF gate or even a WHEN gate.

     

    The programming loop structures of if, while, do, for and more are all high-level programming level abstractions. Instead of expecting the computer to think like you do - you should instead change your thinking to match what the computer (or your choice of programming language) can do.

     

    Say in C, if you want to iterate from 1 to 3, you could do something like this:

    int i = 0;

    while (i < 3) {

      printf("Hello");

      i++;

    }

     

    or you could be nice and use a for loop:

    for (int i = 0;i<3;i++) {

      printf("Hello");

    }

     

    These are all functionally the same and checks the condition at the beginning of the loop.

     

    You can check the condition at the end of the loop - the most silly way would be to use an infinite loop, but break it if i is equal to 3:

    int i = 0;

    while (1) {

      printf("Hello");

      i++;

      if (i==3) {

        break;

      }

    }

     

    or you could use a do, while construct like

    int i = 0;

    do {

      printf("Hello");

      i++;

    } while (i<2);

     

    But be careful, as changing the checking location may change the condition required. But style wise, these are considered "ugly" most of the time, as they are difficult to understand at a glance, especially reading from top to bottom. As to what code is generated, this depends on the compiler and optimisations, so the results may be very similar in terms of actual machine code.

     

    - Gough

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • phoenixcomm
    0 phoenixcomm over 5 years ago in reply to Gough Lui

    Gough Lui No, it's not really the program code that is doing the heavy lifting here. All CPUs have what is known as the instruction set which is in machine code. This controls the gates etc, via microcode whitch is  a very wide word 100bits or more. Now with all that said now you need an assembler, this is where the form comes from. Next is roll your own language, where C is mostly the easiest to code. So starting a the top you must define your keywords( if, do, while, case, switch #define and so forth), you also have to define your standard symbols( <>, {}, [], (), =, ==, +, -, /, *, ++, --, ;  and others) at this point we are not talking about any IO as it is handled in a standard library that is written after the body code is finished and working. after you have your keywords done and working then you need to define a function, no not what it's named but how does it look to the code for instance for a function you need to understand what your input is.   the notation that you would use is called Bacus Nour Form mind you I have written the three below in my shorthand notation.

     

     

    function:

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube