Title: Programming
1Programming
2General Purpose
- The computer is a general purpose tool
- General purpose means it can do more than one
thing - How do we make it do more than one thing?
- make it perform a handful of small tasks that
could be combined to perform more complicated
tasks - allow it to follow instructions to perform the
above tasks - It is programmable (i.e., we can program it)
- A computer program a list of instructions for
the computer - What sort of instructions does the computer
understand?
3Tell me what to do. . .
- Make me a peanut butter and jelly sandwich
- What does this mean to you?
4Really tell me what to do. . .
- Go to the refrigerator
- Open fridge
- If ((no peanut butter) or (no jelly))
- Go to store and buy ingredients
- Remove peanut butter and jelly
- Get bread
- Open bread
- Do twice
- Take slice from bag
- Place slices side by side
- Get knife
- Open peanut butter jar
- Insert knife into jar
- Apply peanut butter to knife
- While surface of bread is not covered with peanut
butter - Apply peanut butter to bread from knife
- Close peanut butter jar
- Open jelly jar
- Insert knife into jar
simple tasks
logic
repetition
5Language of Instructions
- What do we need to know about the target of our
instructions before we can give them? - How do we ask them to do things?
- What do they know how to do?
- What language do they speak?
6Syntax and Grammar
- Syntax the form of what you say
- The grammatical structure (form) of a language
- Grammar defines the words you are allowed to use
and specifies the order in which you can place
them - a grammar defines a syntax
the sandwich grammar
7Language of instructions
- Semantics the meaning of what is said
- Semantics explain how you interpret the results
of parsing - make is a verb
- A verb tells me what action to take
- peanut butter and jelly is an adjective
- An adjective tells me about a noun
- sandwich is a noun
- The noun is the target of my action
- The semantics provide the meaning for each of
these things - Ex when you encounter a make adjective sandwich
you will need to get two pieces of bread, and put
the adjective between the pieces of bread. - How does this relate to computers?
- Beyond the obvious fact that in the future there
will be robots and they will make us sandwiches
8Applied to Computers. . .
- What language does a computer speak ?
- Computers think in binary.
- Internally, they only understand 1s and 0s
- Weve learned that computers can do fancy things
with 1s and 0s - Boolean logic
- Mathematics
- Store and retrieve 1s and 0s
- We need the computer to know that a particular
sequence of 1s and 0s uniquely identifies some
task to do (semantics) - We need to give the computer a series of 1s and
0s - Ideally we (humans) would like a mapping between
English (or something closer to English) and
something that makes sense to the computer
(binary)
9In the beginning
- Early computers were primarily special purpose
mathematic computers. - Computers were designed to perform a particular
arithmetic task or set of mathematic tasks. - Computers that were unable to change their tasks
are hardwired - Hardwiring Using solder to create circuit boards
with connections needed to perform a specific
task (in a larger sense). - Computers that were able to have their tasks
changed required direct hardware modification
by skilled engineers - Change the flow of electricity to run through
different logic paths - Fat-fingering Engineer needed to position
electrical relay switches manually.
10The Programming Language Continuum
- ENIAC
- Used programs to complete a number of different
mathematical tasks. - Programs were entered by plugging connector
cables directly into sockets on a plug-in board. - Set-up could take hours.
- A program would generally be used for weeks at a
time.
11The Programming Language Continuum
- In the beginning To use a computer, you needed
to know how to program it. - Today People no longer need to know how to
program in order to use the computer. - In fact, programming has become easier as well
- programming languages evolve from low-level to
high-level. - Fifth Generation - Natural Languages
- Fourth Generation - Non-Procedural Languages
- Third Generation - People-Oriented Programming
Languages - Second Generation - Assembly Language
- First Generation - Machine Language (code)
High level
Low level
12Representing (Instructions) Programs
- Arithmetic Instructions
- Addition, subtraction, multiplication, division,
and other numeric operations - Data Movement Instructions
- Move numbers from place to place in the computer
- Logical or Comparison Instructions
- Decision making instructions e.g. x lt 10
- Control Instructions
- Controls the sequences in which instructions are
executed e.g. for x 1 to 10 - Input/Output Instructions
- Allow the program to communicate with something
outside the program (user, monitor, network,
other programs)
13Representation of Programs
14Representation of Programs
15Generation I Machine Language
- Machine language programs made up of instructions
written in binary code. - Computers operate in their native language
- Humans translate their instructions into binary
- Each instruction has two parts Operation code,
Operand - Operation code (Opcode) The command part of a
computer instruction. - Operand The address of a specific location in
the computers memory. - You write programs in the lowest-level language
directly for the CPU. - Opcodes do very simple things (the computer is
dumb) and you have it perform more complicated
tasks by combining these instructions.
16Generation I Machine Language
17Generation I Machine Language
- Machine language
- Hardware dependent Could be performed by only
one type of computer with a particular CPU. - That is, each computer (although all speak
binary) might have different arrangements of 1s
and 0s for different instructions. - Different words could have different meanings
- Maybe some computers cant do the same things
- 111 might be add to me, but 010 might be add to
you..
18Generation IIAssembly
- Second Generation - Assembly Language
- Assembly language programs are made up of
instructions written in mnemonics. - Mnemonics Uses convenient alphabetic
abbreviations to represent operation codes, and
abstract symbols to represent operands. - Each instruction (still) had two parts Operation
code, Operand - One-to-one mapping from written instruction to
machine instruction - Still a low-level language
- higher level languages
- Easier on the programmer
19The Programming Language Continuum
- Second Generation - Assembly Language
- Assembly language programs are made up of
instructions written in mnemonics. - Because programs are not written in 1s and 0s,
the computer must first translate the program
before it can be executed. - The translation is a direct translation
- We translate into machine code
- READ OPCODE 001
- num1 Memory 0000 1110
20Assembled, Compiled, or Interpreted Languages
- Assembled languages
- Assembler a program used to translate Assembly
language programs. - Produces one line of binary code per original
program statement. - The entire program is assembled before the
program is sent to the computer for execution.
21Generation III
- Third Generation High-level languages
- Instructions in these languages are called
statements. - High-level languages Use statements that
resemble English phrases combined with mathematic
and logical terms needed to express the problem
or task being programmed. - As before, programs are not written in 1s and 0s,
the computer must first translate the program
before it can be executed. - Instructions are more complicated one may
actually represent several simple opcodes - NOT-Hardware dependent. portable
- So, as long as you can translate the statements
from this language to another machine code, you
can run it on that platform. (more on this
later)
22High Level Language Example
- Pascal Example Read in two numbers, add them,
and print them out.
23Generation IV
- Fourth Generation - Non-Procedural Languages
- Object-Oriented Languages A language that
expresses a computer problem as a series of
objects a system contains, the behaviors of those
objects, and how the objects interact with each
other. - Object Any entity contained within a system.
- Examples
- A window on your screen.
- A list of names you wish to organize.
- An entity that is made up of individual parts.
- Objects pass messages, expose interfaces, can be
inherited from other objects. . . - Some popular examples C, Java, Smalltalk,
Eiffel.
24O-O Language Example
- Object-Oriented Languages example (Simplified
Java?)
25Generation V
- Fifth Generation - Natural Languages
- Natural-Language Languages that use ordinary
conversation in ones own language. - Research and experimentation toward this goal is
being done. - Intelligent compilers are now being developed to
translate natural language (spoken) programs into
structured machine-coded instructions that can be
executed by computers. - Effortless, error-free natural language programs
are still some distance into the future.