# Introduction to Computer Systems

Most of you have been using computers (and other computing devices - cell phones, tablets, etc.) for many years. But, many of you may not know the basics of how a computer system works.

## Computer Systems

### Hardware

Hardware refers to the physical devices that make up a computer. A typical computer system consists of the following hardware:

- Central processing unit (contain in the "box" of the computer) - CPU
- Main memory (contained on the "mother board" - main computer area)
- Secondary storage devices (disc drives, CDs, DVDs, etc.)
- Input devices (keyboards, etc.)
- Output devices (monitor, printer, etc.)

The CPU is made up of small chips - microprocessors. The CPU runs the computer programs that carry out the actions of the computing system.

The main memory stores the programs that the CPU will use. This is called random-access memory - RAM.

Secondary storage devices hold data for long periods of time. Types include disk drives, CDs, DVD, etc.

Input devices collects data people or other devices to use in the computer program that is running. Types include keyboards, mouse, scanner, microphone, digital cameras. Discs and optical drives can also be used as "input" as they hold the data being used in a computer program.

Output devices are those that produce data and information for people or other devices, Printers and display units, plus discs and CDs, DVDs are output as well.

A computer works by running computer programs (software) - instructions that tell the computer what to do. There are many types of computer programming languages that people can learn. We are studying the language Python for this class. Other programming languages include: Java, C++, C#, Cobol, Fortran, etc. (see Table 1-1 in the textbook for a more complete listing).

### Software

Software is a collection of computer instructions that tells the computer what to do and how to do. We also refer to them as computer programs or applications. There are two types of software:

1. System software controls and manages the basic operations of a computer. This includes "Operating Systems", which is a set of programs that control the internal workings of the computer's hardware, manage all of the devices, allow data to be saved and retrieved from storage devices, and allow other programs to run on the computer.
2. Application software are the programs that complete tasks that people need. These types of applications programs may be purchased - such as Microsoft Word, Power Point, spreadsheets, email, web browsers, games, etc., or written by computer "programmers" for a specific task.

## Programming Languages

In order to produce or "write" computer software (a.k.a. computer programs or applications), we will need to use programming languages. There has been a long history in the development and evolution of programming languages (in computer years, of course, relatively speaking).

### History of Programming Languages

- Phase 1 - 1940s - first programming languages, very primitive, wrote programs primarily using simple commands written in binary (0s and 1s)
- Phase 2 - 1960s - low level programming languages - such as assembly, where commands were written in English, and one statement in English translated into one statement of binary code in the computer
- Phase 3 - 1960s-70s - high level programming languages - Cobol, Fortran, etc, one statement written in English translated into several lines of binary code for the computer
- Phase 4 - 1980s - higher level programming languages with stored procedures, and object oriented languages
- Phase 5 - 1990s - the internet age where programming languages were built to specifically run well on the web.

## How the Computer Stores Data/Program

Computers are electronic - they only understand electric currents - "on" or "off". We represent this on/off stages in the computer through a BIT (binary digit). Each BIT is either "0" or "1". We group these BITs together in groups of 8 and call this a BYTE. A BYTE stores one letter or special character or small number. Patterns of 8 BYTEs are used to store computer programs (English statements convert into binary BYTEs), and data (stored as BYTEs). Computers today have millions and billions of BYTEs of memory.

Since we are using only 0s and 1s in our computer - everything is done in the Binary numbers system. The only allowable numbers in Binary - are 0 and 1. When we put the binary digits (BITs) together into our BYTEs we need to be to "decode" what the BYTE value is actually being stored. We may combine BYTEs to store larger numbers as necessary.

It's always "weird" to think that letters and special characters are stored as 0s and 1s. When a character is stored in memory it is converted to a numeric code, and then converted to Binary to be stored in the computer. ASCII - American Standard Code for Information Interchange lists the various "codes" for letters and characters. However, ASCII only has 128 possible codes, and so we now use UNICODE which can represent many more numbers, characters, etc.

## More on the CPU

The CPU is made up of many parts: the input area (unit), the output area (unit), and the processing area (unit). The input area and output areas hold data either coming into the CPU to be used in a program (input area), or data going to the printer, screen or external storage device (output area). The processing unit itself brings in the computer program stored on an external device, and follows each line of code one line at a time. The CPU may carry out the functions that the computer program specifies such as mathematical tasks - adding, subtracting, etc.; it will move data from one internal memory location to another (inside the CPU - or from the input unit or to the output unit). It will also carry out such tasks as looking at logical comparisons - "=", "<", ">", etc.

## How the Computer Works

Remember - we have TWO things that we must have for the computer to work - a Computer Program (written in a specific programming language), and Data (that will be used in the computer program).

First - Computer programs are written in a particular computer language (in English, or of course if you are from another country the equivalent language of that country). The rules of how a particular programming language is written is called its SYNTAX. Each programming language has it's own SYNTAX rules - you MUST follow the SYNTAX rules to properly write the computer program in English. We write computer "statements" that will tell the computer what we want it to do for us.

Second - the Computer program that is written in the programming language must be either "Compiled" or "Interpreted". Compiled means that each line of written programming code - which is called SOURCE CODE - is translated into the binary equivalent (everything in 0s and 1s) - this is now referred to as MACHINE CODE (your programs in 0s and 1s). Machine code is the ONLY code that the computer understands and can be done with the electronic switches for 0 and 1. "Compiled" means that every line of English code that you write is translated all at once into binary. Then the computer decides if it understands the binary code that was generated. If it finds errors (in other words - the computer can't understand the 0s and 1s patterns), then it cannot work, and sends back a message that there are SYNTAX errors in the original program that you wrote. As the person who wrote the original program, you need to FIX your SYNTAX errors in the program. Error messages will pinpoint where the SYNTAX problems are in your program. You must rewrite your program to fix the errors and resubmit the program to the Compiler. You may get your program back again if you didn't fix all of your SYNTAX errors correctly. You need to refix the program and recompile until you fix all of your SYNTAX errors. With the Interpreter - the computer takes one line of code that you wrote and translates it and if it finds an error - it sends you a message for that one line of code only. Again - you fix the SYNTAX error for that one line of code, resubmit, and the Interpreter keeps going with each line of code until everything works.

Once the program has been Compiled or Interpreted correctly, then the computer can "run" or "execute" your computer program. This means that the computer can take each line of your program (now in Binary) and follow what your computer programming statement tells it to do. This now many include data - maybe from the keyboard, or from an external storage source (such as a disc) to make the code produce what it needs to. As the computer runs - ir uses data throughout the program to complete its' tasks. At the end of "running" or "executing" the program - it will produce the Output that you desired - something printed on the screen, something printed to the printer, or something stored on disc, CD, DVD, etc. HOWEVER - you may NOT get the correct output that you expected from your program!!! This means that you have a LOGIC ERROR. A logic error is one where you did NOT follow the correct logic in writing your computer program originally. For instance - you ask to read data that doesn't exist, or you have a mathematical statement that doesn't actually work, etc. You then need to "debug" your program. With LOGIC errors you need to go back to your original program, figure out where you made your "logic" error, rewrite the program, send the program back through the interpreter to be sure your SYNTAX is correct, and then rerun the program - Hopefully producing the correct output that you expect!! Many programmers make the mistake of getting output but not actually checking its validity!!!!

## More on Programming Languages

Each high-level language has it's own set of predefined words that the programmer (you) needs to use to write the program. The words that you must use are called "key words" or "reserved words". Each key word has a specific meaning (tells the computer to do particular action) and cannot be used for any other purpose. Reserved words again are used for special purposes and cannot be used for "data" words.