ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Books, Literature, and Writing

Computer Programming

Updated on October 17, 2015

How Programming Works(OOPS)

On its own, a computer isn't very smart.

A computer is essentially just a big bunch of small electronic switches that are either on or off. By setting different combinations of these switches, you can make the computer do something, for example, display something on the screen or make a sound. That's what programming is at its most basic—telling a computer what to do.

Of course, understanding which combination of switches will make the computer do what you want would be a difficult task—that's where programming languages come in.

What Is a Programming Language

People express themselves using a language that has many words. Computers use a simple language that consists of only 1s and 0s, with a 1 meaning "on" and a 0 meaning "off." Trying to talk to a computer in its own language would be like trying to talk to your friends by using Morse code—it can be done, but why would you?

A programming language acts as a translator between you and the computer. Rather than learning the computer's native language (known as machine language), you can use a programming language to instruct the computer in a way that is easier to learn and understand.

A specialized program known as a compiler takes the instructions written in the programming language and converts them to machine language. This means that as a Visual Basic programmer, you don't have to understand what the computer is doing or how it does it. You just have to understand how the Visual Basic programming language works.

What is C?

The simplest way to define C is to call it a computer programming language, meaning you can write software with it that a computer can execute. The result could be a large computer application, like your Web browser, or a tiny set of instructions embedded in a microprocessor or other computer component.

The language C was developed in the early 1970s at Bell Laboratories, primarily credited to the work of Ken Thompson and Dennis Ritchie. Programmers needed a more user-friendly set of instructions for the UNIX operating system, which at the time required programs written in assembly language. Assembly programs, which speak directly to a computer's hardware, are long and difficult to debug, and they required tedious, time-consuming work to add new features

Thompson's first attempt at a high-level language was called B, a tribute to the system programming language BCPL on which it was based. When Bell Labs acquired a Digital Equipment Corporation (DEC) UNIX system model PDP-11, Thompson reworked B to better fit the demands of the newer, better system hardware. Thus, B's successor, C, was born. By 1973, C was stable enough that UNIX itself could be rewritten using this innovative new higher-level language

The C programming language is a popular and widely used programming language for creating computer programs. Programmers around the world embrace C because it gives maximum control and efficiency to the programmer.

If you are a programmer, or if you are interested in becoming a programmer, there are a couple of benefits you gain from learning C:

  • You will be able to read and write code for a large number of platforms -- everything frommicro controllers to the most advanced scientific systems can be written in C, and many modern operating systems are written in C.
  • The jump to the object oriented C++ language becomes much easier. C++ is an extension of C, and it is nearly impossible to learn C++ without learning C first.

In this article, we will walk through the entire language and show you how to become a C programmer, starting at the beginning. You will be amazed at all of the different things you can create once you know C!

The Basics of C Programming

Let's walk through this program and start to see what the different lines are doing (Click here to open the program in another window):

  • This C program starts with #include <stdio.h>. This line includes the "standard I/O library" into your program. The standard I/O library lets you read input from the keyboard (called "standard in"), write output to the screen(called "standard out"), process text files stored on the disk, and so on. It is an extremely useful library. C has a large number of standard libraries like stdio, including string, time and math libraries. A library is simply a package of code that someone else has written to make your life easier (we'll discuss libraries a bit later).
  • The line int main() declares the main function. Every C program must have a function named main somewhere in the code. We will learn more about functions shortly. At run time, program execution starts at the first line of the main function.
  • In C, the { and } symbols mark the beginning and end of a block of code. In this case, the block of code making up the main function contains two lines.
  • The printf statement in C allows you to send output to standard out (for us, the screen). The portion in quotes is called the format string and describes how the data is to be formatted when printed. The format string can contain string literals such as "This is output from my first program!," symbols for carriage returns (\n), and operators as placeholders for variables (see below). If you are using UNIX, you can type man 3 printf to get complete documentation for the printf function. If not, see the documentation included with your compiler for details about the printf function.
  • The return 0; line causes the function to return an error code of 0 (no error) to the shell that started execution. More on this capability a bit later.

Monday, October 12, 2015

RAM ,Cache and Registers

There are several kinds of storage in a computer:

  • Persistent storage like hard drives, DVD-ROMs, and flash memory, which keep their contents even when the computer is turned off. These are relatively slow to access, but very big and very cheap compared to the others.
  • Random access memory, which loses its contents when the computer turns off. RAM is smaller and more expensive than hard drives; you might have 300 GB of disk space but only 1 GB of RAM.
  • Cache memory, which stores the commonly used parts of RAM for quick access. This is usually divided into multiple levels, and some levels might be inside the CPU package.
  • Registers, which are located in the core of the CPU and take no extra time to access, but also very limited in quantity.

Top to bottom, each kind of storage gets smaller and more expensive, but also closer to the CPU and faster to access. As CPUs have gotten faster and faster, the speed of memory and disks hasn't advanced at the same rate, so it's important to use registers as much as possible to get the best performance.

Chache And Registers

Caches are designed to alleviate this bottleneck by making the data used most often by the CPU instantly available. This is accomplished by building a small amount of memory, known as primary or level 1 cache, right into the CPU. Level 1 cache is very small, normally ranging between 2 kilobytes (KB) and 64 KB.

The secondary or level 2 cache typically resides on a memory card located near the CPU. The level 2 cache has a direct connection to the CPU. A dedicated integrated circuit on the MB the L2 controller, regulates the use of the level 2 cache by the CPU. Depending on the CPU, the size of the level 2 cache ranges from 256 KB to 2 megabytes (MB). In most systems, data needed by the CPU is accessed from the cache approximately 95 percent of the time.


    0 of 8192 characters used
    Post Comment

    No comments yet.