Date post: | 12-Jan-2016 |
Category: |
Documents |
Upload: | brook-kelly |
View: | 218 times |
Download: | 0 times |
AS ComputingAS Computing
Introduction to Introduction to ProgrammingProgramming
What is a Computer Program?
A list of instructions that a computer must work through, in a logical sequence, to carry out a specific task
Computer programs are written in a programming language
Programming Languages
Many different languages and many different versions of same language
Each language has a vocabulary and rules that define arrangement - SYNTAX
Fewer words to
learn than aforeign language
Rules are more
rigid than a foreign language
Generations of Programming LanguagesComputers have been around since 1940s
Early computers programmed by changing switch settings to represent binary data
Bletchley Park
Alan Turing
Difference Engine – Charles Babbage
0010100100100101001001110110101011010100111110110100001010101010110101010101011011011010
First Generation – Machine Code
Processors can only work with Binary Digits
All instructions given to a computer must be in a pattern of zeros and ones
Second Generation – Assembly Language
Use words rather than 0s and 1s
Simple translation of 1 word to 1 machine code instruction
Uses mnemonics:LDA Load AccumulatorSTA Store AccumulatorADD Adds to AccumulatorSUB Subtracts from Accumulator
Low Level Languages;// ADDRESS OPCODE ASM; ----------------------------------$0000 $2A82 GOTO hifi_main$0004 $ delays_delay_1us:$0004 $0000 nop$0005 $0000 nop$0006 $0008 RETURN$0007 $ delays_delay_5500us:$0007 $300F MOVLW 15$0008 $1303 BCF STATUS,RP1$0009 $1283 BCF STATUS,RP0$000A $00F0 MOVWF STACK_0$000B $30FF MOVLW 255$000C $00F1 MOVWF STACK_1$000D $ delays_L_8:$000D $0BF0 DECFSZ STACK_0, F$000E $2810 GOTO delays_L_9$000F $2813 GOTO delays_L_10$0010 $ delays_L_9:$0010 $0BF1 DECFSZ STACK_1,F$0011 $2810 GOTO delays_L_9$0012 $280D GOTO delays_L_8$0013 $ delays_L_10:$0013 $303E MOVLW 62$0014 $00F0 MOVWF STACK_0$0015 $ delays_L_11:$0015 $0BF0 DECFSZ STACK_0, F
Machine Code & Assembly language are:
Processor Processor DependantDependant
Collectively known as Low Level Languages
Third Generation - High Level Languages
Problem oriented languages, easy to understand
if Age >=17 Then Showmessage(‘Can drive a car’)
Based on what the program must do, rather than what the processor and memory do
PORTABLE – programs can be used on different types of computer BASIC JAVA PASCAL C
Many Different High Level Languages
Written to cope with the demands of specific types of problem:
Business Applications
Databases
Web Pages
High Level Language Classifications
Procedural or ImperativeUse a sequence of instructions, executed in a particular order
Object OrientedUse objects and inheritance
DeclarativeProlog, SQLFacts and rules based
Translating High Level Translating High Level LanguagesLanguages
Easy for people to use, but computers can not understand them
The translation from high level code to machine code is a more complex process than for assembly language
There are 2 types of Translator:
INTERPRETER
COMPILER
Programming Constructs
Most high level languages construct their statements in a similar way:
SEQUENCESEQUENCE
ASSIGNMENTASSIGNMENT
SELECTIONSELECTION
ITERATIONITERATION
Assignment
Age = 34Age = 34
Sets the variable Age to the value of 34
Assignment is fundamental to programming
Types of Variables
IntegerLong IntegerReal Number
Number with decimal point
StringAlphanumeric
BooleanYes/No or True/False
Data TypesCurrent Rate of VAT
Real
Todays DateString / Date?
Total takings at a shopReal
If a school has a sixth form or notBooleans
Number of Pupils in a SchoolInteger
Selection - If
Compares values and decides outcome
If Age < 17 Then
Showmessage(‘Under Age to drive’);
Else
Showmessage(‘Old enough to drive’);
End If
Iteration
Often useful to repeat a section of code
Counting the number of letters in a word
Keeping an object moving, until it reaches a barrier
Doing something until a condition is met
Doing something a certain number of times
Doing something while a condition is true
2 Methods of Iteration
Count Controlled Count Controlled
Condition ControlledCondition Controlled
Iteration
Do while x < 10
x = x + 1
MessageBox x
Loop
For x = 1 to 10
Messagebox x
Next x
Count ControlledCount ControlledCount ControlledCount Controlled
Condition ControlledCondition ControlledCondition ControlledCondition Controlled