A computer program is a set of instructions that tells a computer how to perform a task. Depending upon the language used, program code my be difficult for humans to read and understand. A high-level programming language like Beginners All-Purpose Symbolic Instruction Code (BASIC) was designed to easy to read by humans. Unfortunately, some versions of basic have been built upon to provide way more power than originally intended, making them difficult to understand.
A low-level language like C, was designed to be powerful and efficient, but not so easy to read or understand except by experienced programmers.
High-level programming languages get their ease of understanding by hiding the complexity from the user. Behind the scenes, each high-level language statement, actually calls upon many low-level language statements.
The "lower" a programming language is, the closer it is to the binary 1s and 0s that computers actually use. People who program microprocessors and microcontrollers at the lowest level use assembly language, which is one step above binary. People who design microprocessors and microcontrollers use register transfer code. An example of a register transfer statement is shown below.
This is by no means the most complex register transfer code statement that can be designed.
Like most things, computer programming gets easier the more you do it. But initially it starts off difficult to understand. However, one type of "programming" that is very easy to understand is flow charting. To get an understanding of computer architecture you'll need a least an understanding of flow charting.
Not only is flow charting very easy to understand, it's also very powerful, not only for understanding computer operation, but also in general life problem solving and decision making. So lets take a look at how flow charts work.
Flow charting uses four basic shapes as shown below.
Shown below is the flow chart for a simple sequential program that adds two numbers.
This program has limited use because the inputs are constants and there is no output. The inputs to the program shown below are variables (from an input device like a keyboard), and the result of the program's execution is output (to an output device like a screen).
Most programs have to make a decision at some point. In flow charting a diamond is used to show a decision. Shown below is the flow chart for a program that decides weather an item should be purchased or not based upon price. If the price is greater than $10, the item will not be purchased. If the price is $10 or less, the item will be purchased.
The flow chart below makes a similar decision as the one above except if the price of the item is greater than $10 it requests a discount. Then another decision diamond is used to test whether the discounted price is greater than $10.
Any time a program changes its sequence of flow based upon a decision box, that's called a branch.
The flow chart below makes a similar decision as the one above except it just keeps requesting a discount until the proprietor gives a discounted price of $10 or less. Then the item will be purchased. This type of flow is called a loop.
Of course you can see a bug in the program, if the proprietor never gives a discounted price of $10 or less, the program will be stuck in the loop forever. This type of bug is called an infinite loop.
The program below fixes the bug by implementing a loop counter.
Each time a request is made for a discount, this program increments a discount request counter. Before making a request for a discount, the second test diamond checks the request counter. If the request counter indicates less than 10 previous requests for a discount have been made, a request for a discount is made. If 10 previous requests for a discount have been made, the program ends. I think if 10 requests for a discount have been made and the proprietor still refuses to give a discount that brings the price down to $10, its time to give up.
You can see how easy it is to understand and design a program flow chart and how powerful they can be. Flow charts can be useful in general life problem solving and decision making. In fact, flow charts are used to describe many business and manufacturing processes. There are many graphical flow chart design applications.
Learn more at amazon.com