You are on page 1of 3

Introduction to Computers and Programming CIS 150 Introduction to Computer Logic and Programming Programs A program is a set of instructions

ons that a computer follows to perform a task Programs are commonly referred to as software (as opposed to the physical components called hardware) A programmer or software developer designs, creates, and tests computer programs before they are deployed in a production environment Programs and the CPU A computer is said to be running or executing a program when it carries out that program's tasks The central processing unit (CPU) is the hardware component that executes the instructions in a program Early CPUs were very large, composed of electrical and mechanical components (vacuum tubes, switches) Modern CPUs are small chips known as microprocessors and are much more capable Programs and Memory / Storage Main memory, or random-access memory (RAM), is a hardware component used to store currently-running programs and the data these programs are using The CPU has quick access to data stored at any random location in RAM volatile: does not keep its state when powered off Secondary storage holds data and programs for long periods of time Programs and data must be loaded into main memory before the CPU has access to them Examples include hard disks, floppy disks, USB flash drives, and optical discs (CDs and DVDs) How a Computer Stores Data Each memory location is capable of holding a byte of information A byte is made of eight smaller memory locations known as bits (binary digits) Each bit can hold a value of 0 (off) or 1 (on), often represented by a negative or positive charge The eight bits in a byte can be visualized as a set of eight switches The Binary Numbering System The binary numbering system describes how a number in our normal decimal form can be encoded in 0s and 1s Each place in a binary number represents a power of two The rightmost digit has a value of 20, or 1 In a byte, the leftmost digit has a value of 27, or 128 A single byte can hold one of 28, or 256, unique values (from 0 to 255), with the decimal value being the sum of the values of the 1-valued bits Any device that works with binary data (also known as digital data) is referred to as a digital device Binary System Example Consider the binary number 01001101 The 1 in the first place from the right: 1 * 20 = 1 The 1 in the third place from the right: 1 * 22 = 4 The 1 in the fourth place from the right: 1 * 23 = 8 The 1 in the seventh place from the right: 1 * 26 = 64 Value: 64 + 8 + 4 + 1 = 77 Introduction to Computers and Programming (CIS 150 Chapter 1) Page 1 of 3

Bytes for Numeric Storage Most computers use multiple bytes to store much larger numbers Two bytes = 16 bits = 216 combinations (65,536) Four bytes = 32 bits = 232 combinations (over four billion) Negative numbers are encoded differently than positive numbers (using the twos complement technique) For numbers with a fractional component (also known as real numbers), computers usually set aside some of the bits for the number and the rest of the bits for the power of ten by which to multiply the number (a system known as floating-point notation) Bytes for Character Storage The most prominent encoding for characters from the early 1960s onward is ASCII (the American Standard Code for Information Interchange) Specifies 128 numeric codes that represent various printable and nonprintable characters Example: an uppercase A is represented by the number 65 (or in binary, 01000001) To support international characters, newer programs may use the Unicode character set Bytes for Other Data In a picture file, each byte might represent all or part of the color of a specific pixel in an image In an audio file, the song or speech is broken up into samples that are represented in binary numbers The greater the number of samples, the higher the quality of the sound CD quality: over 44,000 samples per second Programming and the CPU A CPU understands a finite set of instructions written in binary form (machine language) Arithmetic Comparison Reading, moving, storing data in main memory The set of machine language instructions for a particular CPU is known as the CPUs instruction set Each instruction goes through the fetch-decode-execute cycle fetch: read the next instruction from memory decode: determine which operation to perform execute: perform the operation Assembly Language An alternative to using binary representations of CPU instructions is assembly language Short words known as mnemonics represent the instructions for a CPU Example: mul for multiply Example: mov for moving a value to a location in memory A program called an assembler translates assembly language code to machine language Referred to as a low-level language because it relates closely to the machine language for a specific type of CPU High-Level Languages Programmers prefer to use languages that do not require extensive knowledge of the machine language or assembly instructions A high-level language uses words that are easy to understand to represent the large number of instructions needed to carry out common program operations Examples include Ada, BASIC (and Visual Basic), FORTRAN, COBOL, C, C++, C#, Java, JavaScript, Pascal, Python, and Ruby

Introduction to Computers and Programming (CIS 150 Chapter 1)

Page 2 of 3

Elements of High-Level Languages Key words / reserved words: words that have special meanings and cannot be used for other purposes Operators: perform operations on data Punctuation: characters that separate or group instructions or portions of instructions Syntax: the strict rules that must be followed to form programs in a language Statements: the individual instructions in a program Translation The CPU only understands instructions written in machine language High-level programs must be translated into the machine language for the CPU that will execute the instructions A compiler converts the high-level language program into an executable program containing all of the instructions in machine language that can be executed without the compiler An interpreter translates and executes each individual instruction one at a time Source Code and Syntax Errors Code written in a high-level programming language is known as source code Source code may be entered in a plain text editor or one that recognizes and highlights the syntax of specific languages If a source code file contains a syntax error (an error in the use of the language), the compiler or interpreter will display an error message All syntax errors must be corrected before the translation process can complete IDEs An integrated development environment (IDE) combines several programming tools into one package Source code editor with syntax highlighting Compiler or interpreter Tools to test and debug a program Examples: Visual Studio, Eclipse, NetBeans, Dev-C++, jGRASP, Xcode Software Types System software includes programs that control and manage basic computer operations Operating systems Utility programs Software development tools Application software allows the user to perform everyday tasks

Introduction to Computers and Programming (CIS 150 Chapter 1)

Page 3 of 3

You might also like