What is a computer program What is a










- Slides: 10

What is a computer program?

What is a Computer Program? • A solution to a problem? • A confusing mess? • A sequence of computer instructions?

What is a Computer Program? • A computer program is a sequence of statements written in a formal language and executed in sequential order • There are some statements that can jump to another position in the sequence

Languages • Languages have • syntax (the way in which words can be combined) and • semantics (roughly, the meaning; the relation between the language and the world) • Natural language • Languages we speak: English, Spanish, Chinese, Finnish, etc • Can grow (infinitely? ) • Can be redundant and ambiguous • Pronouns • Formal language • A language we invent for some particular reason (like a programming language) • Some might be meant to be machine interpretable • Can grow but slowly and not infinitely • Can not be redundant or ambiguous • Pronouns • Programming languages are formal languages

Software Languages • High level language • Highest level of abstraction • C#, Java, Python, C++ • Mid/Low level language • Less abstraction – closer to the hardware • C • Assembly language • No abstraction • Mnemonics for instructions, memory location names • Machine code (hardware) • These are the binary op codes (instructions) that execute on the hardware

Software Languages "Vaporators? Sir, my first job was programming binary loadlifters—very similar to your vaporators in most respects. "

CPU Instruction Set • The instructions that the computer understands are its native Machine Language instructions (assembly language programs are written using these instructions directly). • 8008 Instruction Set

Assembly Language A very small assembly language program to add two numbers from memory and place the result back in memory would look like this: LAM 5 E 00 LBM 5 E 01 ADB LMA 5 E 02 HLT ; Load data from address 5 E 0016 into A ; Load data from address 5 E 0116 into B ; Add A and B and put result in A ; Move data from A to address 5 E 0216

What is a CPU Good At? • Remembering things • Moving values to/from memory • Computer moves things from CPU bus to display or network • Simple math operations • Add, subtract • Multiply, divide are sometimes provided in separate floating-point processor • Repetition • Over, and over, …. . and over again • Low level decision making • Compare two values, jump on condition • The job of the programmer is to implement an algorithm using these simple instructions to do the job that needs to be done • Think about long division – step by step process (algorithm) to divide two numbers

Exercises in Describing an Algorithm • What are the steps to? • Make a peanut butter and jelly sandwich • Sort playing cards • Sort cards by • suit (spades, hearts, diamonds, clubs) and • Rank (A, K, Q, J, 10 – 2) • Count Legos by color • Counts of each color of Legos • Long division • These processes must described in simple steps and must be complete so that someone else (even a computer) could follow them • Think about how you would tell another person (or a computer) to do this • Write down the steps • Computer programming is a written form of art