http://www.bobyhermez.com/wp-content/uploads/2012/05/banner-impact-768-90.gif

Programming Style (Part 1)

PREFACE

The Computer System
The word “system” is very important when we talk about computers. An effective computer system is an interconnected set of components working toward a commond end. The system consists of two main categories- hardware and software.
Hardware consists of the actual pieces of equipment-keyboards, screens, the components inside the boxes, printers, and so forth.

Software is the instructions that direct the hardware – telling it how to perform tasks of us. One is not much good without the other. Without software the computer is nothing but expensive paperweight

Hardware
Computers come in all sizes from pocket-sized to building-sized. While the larger systems can process more data at a faster rate, all computers are functionally quite similar. They have roughly the same categories of components that operate in about the same way.

Access to Data
Almost any operation in the computer involves accessing data. There are two, and only two, types of data access: read and write. A computer read operation is similar to reading a book. You look at the words on the page and copy them to your mind, but they are not removed from the page. Playing back an audio or video tape is a read operation. You may play it back as many times as you want; the data is not destroyed. A read access, then, simply makes a copy of the data while leaving the original intact.

A computer write operation is similar to writing on a sheet of paper, except that a computer write operation actually erases what was there before. Recording an audio or video tape is a more complete example of a write operation. The previous data is erased, and new data is recorded. A write access, then, replaces data where the write occurs.

The CPU
The heart of any computer system is its central processing unit (CPU). The CPU has three main functions: control, arithmetic operation, and logical operations. In its control function the CPU takes your instructions, one at a time, and following each, directs the rest of the computer system. It is your supervisor inside the system. You are the ultimate boss. You either write the instructions or load some other prewritten ones, but you give those instructions to the CPU and have carry them out.

Once you give a set of instructions to the CPU and direct it to follow those instructions, you are no longer in control of the computer; the CPU is. Control will be returned to you only after those instructions are finished or some error condition forces the CPU to halt them. It is important to remember that the CPU is not some intelegent being but a brainless machine. It handles one instruction at a time, looking neither forward nor back, and never evaluating the propriety or outcome of the instruction. You would know to subtract deductions from an employee’s paycheck; the CPU would just as happily add them if it was so directed. It would throw itself off a cliff if that was one of the instructions.

Analyzing the computer’s output and making sure it has the proper instructions is, of course, up to you. You cannot expect any intelligent help from the CPU. Many of the operations done by the computer are actually performed within the CPU. For these operations, it directs itself. For example, Arithmetic operations-addition, subtraction, multiplication, and division–are performed within the CPU. Obviously, a computer mus perform arithmetic. Calculating a paycheck by multiplying the employee’s hours by that employee’s pay rate and subtracting various deductions is a typical example.

Logical operations–comparisons–are also performed within the CPU. Is that larger than that? Are these two items equal? You would probably also use to logical operations in producing a paycheck. To determine whether to pay overtime, you would compare the employee’s hours to 40. To find the data on the employee’s deductions, you would compare the employee’s name to the name in your file of employees.

Main Memory

Having a CPU is a start, but you still need other components in your computer system as well. For example, where do the instructions come from that the CPU is following? Where does the CPU put the data that it is processing or the results of it’s efforts? Main memory stores two types of things: the current set of instructions that the CPU is following, and the data that these instructions manipulate.

Physically, main memory is made up of thousands or millions of location – sets of components that store these individual pieces of data. This construtions allows random access to main memory; the CPU can reach any single location in memory– one letter, one number, or one instruction. That sounds reasonable and, in fact, it is necessary that the CPU be able to do that to get anything done. Yet some other storage systems, as we shall see, will not allow this individual access. This makes it hundreds in a twentieth of a milionth of a second. This makes it hundreds or even thousands of thimes faster than other storage systems.

Main memory has limitations, however. It is relatively expensive and it is volatile, meaning that when the power is turned off, it forgets. Therefore you use main memory only for active, and data associated with it.(This may be a few programs with multitasking computers–meaning those that can run more than one program concurrently) When you finish with a program, you replace it in main memory with a new one.

Secondary Storage

Disks, both hard and floppy, are the most common example of secondary storage. Unlike main memory, secondary storage is permanent. You can change the data there any time you want, but unless you do, the data will remain forever. Secondary storage is also relatively cheap; therefore you typically have lots of connected to the system, often hundreds of times the main memory capacity.

This sounds so good that perhaps you should forget main memory and work only with secondary storage. Secondary storages, however, is slow—hundreds of times slower than main memory. More importantly, secondary storage is only accessible in chunks called physical records, or sectors or blocks depending on the device. These physical records, or sector or blocks depending on the device. These physical records may be from about eighty to thousands of characters long. In order to work with data effectively you must be able to access individual characters, or numbers or instructions, which you can only do in main memory.

You use both storage systems, then, in the computer. You do your work using main memory. The data or instructions you need are loaded into main memory and processed. If you wish to save these things permanently, you read them from main memory and write them to secondary storage typically hard or floppy disks. This then allows you to write the instructions and data for the next project into main memory and process them.

For example, if you had data in secondary storage that you wished to change, a payroll record perhaps, your instructions to the CPU would direct it to read the physical record or records containing that payroll record into main memory, write the change to the individual characters in the record (the copy in main memory, of course), and then write the physical record back to its original space in secondary storage, replacing the original physical record. Your change would then be made permanent.

Input and Output
Even with all this, the system still lacks some essential items—ways for us humans to communicate with it. The most common type of input device is the keyboard, although there are others such as the mouse, the optical scanner, and so forth. Screens and printers are the most common types of output devices

Following Instructions
The instructions controlling the CPU and the data that the CPU works with must be stored in main memory. If we have them in secondary storage, they must be read from there and written to main memory. The CPU has a number of small storage circuits called registers. One of these registers, the instruction register, is capable of holding a single computer instruction—only one. The instruction currently being followed must be these so that the CPU can react to it.

The CPU has a few(perhaps 4 to 16, depending on the CPU) other registers called data registers. These store the data that the CPU uses in arithmetic or logical operations. These are only few of thes registers, so data must continuously be moved in and out of them.

To perform a single instruction, the CPU must fetch the instruction from main memory, put it in its instruction register, interpret it, and perform it. That instruction will then be replaced in the instruction register by the next instruction. Since only a copy of each instruction is written to the instruction register, the orisinil is not destroyed—it is still in main memory—but it is no longer visible to the CPU. The CPU can “see” only one instruction at a time.

That fact, or limitation, will be very important to you as you program. Humans can see the “big picture”—what led up to this action and what actions will follow. Computers cannot. They can see only the present, which to them is about a fifty-millionth of a second. If you could instruct your computer to take a step forward, it could not see that the result of that action might be to plunge off a thousand-foot cliff; it would simply step forward. Directing the hardware to perform some useful, reasonable task is up to you. The computer cannot help you

A Simple Addition Operation
To us, adding two numbers together, such as 12 and 25, is a simple operation. To the computer, it involves at least three instructions, and a number of operation. The added complication, though, is more than made up for in speed and accuracy.
Let us take a graphical look at how the computer might do it. This is only part of a program; somehow the numbers must have been placed in main memory, and something must be done with the result after it is calculated.

1.Fetch the second instruction and put it in the CPU’s instruction register.
2.That instruction directs the CPU to fetch the value from location 6016 and put it in a data register.
3.Fetch the second instruction and put it in the CPU’s instruction register, replacing the first one
4.That instruction directs the CPU to add the contents of location 6016 to the contents of the data register
5.Fetch the third instruction and put it in the CPU’s instruction register, replacing the second one.
6.That instruction directs the CPU to move the contents of data registers to location 6017, replacing the value there.

SOFTWARE

Hardware you can touch; software you can’t. Software may be stored on various media, disks or paper perhaps, but software is simply ideas—instruction to make the hardware perform for you. A set of instructions is called a program. Some program figure out the payroll, others fly aircraft, still others assist you in writing reports or books. Software is divided into two categories: system and application. You are probably most familiar with application software—that written to perform specific tasks for individual users of the computer system. Some example are accounting, spreadsheet, word processing, and game programs. Most if the programs you write(and all that you will write from this text) will be applications
System software provides service for all the users of the computer system. It has two main objective. The first is to deliver the hardware’s resources to you in a relatively simple manner. For example, to print some characters at the printer, the CPU must know to which wires the printer is connected, in what fashion and at what speed it should send the characters, whether the printer is currently busy printing characters previously sent to it (and if so, to wait until it I free), and how to react to error conditions in the printer channel. All these details must be considered for each character printed, and doing so involves many computer instructions.

Since printing is such a common activity, you do not want to have to write those instructions into every program that uses the printer. Instead, the system designers have written printing routines into the system software that we all use. Our application program designates a set of characters and passes them along to the system-software printing routine. When that routine is finished, it passes control back to our application program, which continues on with its task.

The second main objective of system software is to provide compatibility between different hardware configurations. Computers within the same family often have different printers or screens, for example. A single configuration of the system software will allow the same set of application program instructions to accommodate the different hardware. This facilitates portability of application software—the ability to run the same application software on different hardware configurations

Operating Systems
An operating system, is a set of system-software programs. Your application program will have to make use of, and be compatible with, the operating system in use on your computer. Unfortunately, there is not just one operating system. Life would be too simple if you could write application software that would run on any machine. Some of the popular operating software are Linux, MS-DOS, OS/2, MACINTOSH, Windows, and XENIX on microcomputers; and UNIX on micros, workstations, and midrange computers. Many manufacture of midrange and mainframe computers supply their own operating system. IBM, for example, has OS/400 for its AS/400 line of midrange computers, and DEC has VMS on its VAX machines.

The Nature Of Data
Humans and computers are different. One look at a representative sampling of each group will tell you that. We and they also process and store data differently. We do not fully understand how the human brain works, but we know exactly how the computer operates, and the way the computer stores and works with data is significantly different from the human way.

In many cases we are shielded from those difference because data is automatically translated back on its way out to us. We never really see data in its pure computer form. We do, however, have to understand something about that form in order to appreciate what happens to our data inside the computer, as well as to ensure that we can make the most efficient use of the computer.

Number System: Ours and The Computer’s
Our decimal number system is based on 10 number symbols, 0 through 9. (Decem means 10 in latin.) We have all grown up with numbers like 6 or 49 or 3,017, which combinations of our 10 basic symbols. It would be hard for us to imagine those values expressed in any other way. Our 10 symbol system developed quite naturally because our earliest counting machinery had only 10 different elements, the ten fingers on a human’s hands.

Each of the value 0 though 9 can be expressed with one symbol. To express numbers greater than 9 in the decimal system, we use combinations of symbols and positional determines its magnitude. In decimal, the first (rightmost) position tells how many ones, the second (to the left) tells how many tens, and so forth. The value 24 is two tens and four ones. Similarly, 4,680 means four thousands, six hundreds, eight tens, and no ones.

 

Can’t find what you’re looking for? Try Google Search!!




331 days ago by in Software | You can follow any responses to this entry through the RSS feed. You can leave a response, or trackback from your own site.

You Might Also Like Our Friend's Posts