programming languages€¦ · computer languages are used to develop programs. ... this is a...

41
PROGRAMMING LANGUAGES Marlene Galea

Upload: others

Post on 09-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

PROGRAMMING LANGUAGES

Marlene Galea

Page 2: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

What is a computer language?

A computer language involves a vocabularyand set of grammatical rules for instructing a computer to perform specific tasks.

Computer languages are used to develop programs.

Page 3: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

The CPU Instruction Set

the complete set of all the instructions in machine code that can be recognized and executed by a central processing unit.

Page 4: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

The CPU Instruction Set

Examples of instruction set

ADD - Add two numbers together.

COMPARE - Compare numbers.

IN - Input information from a device, e.g. keyboard.

JUMP - Jump to designated RAM address.

JUMP IF - Conditional statement that jumps to a designated RAM address.

LOAD - Load information from RAM to the CPU.

OUT - Output information to device, e.g. monitor.

STORE - Store information to RAM.

Page 5: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

LOW LEVEL LANGUAGES

Page 6: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

What is a Low Level Language?

This is a programming language that that provides little or no abstraction from a computer's instruction set architecture

Page 7: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Machine Code

• Computer can directly execute machine code

• Humans find it very difficult to write in machine code

• They are written to run on a specificplatform.

Page 8: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Advantages and Disadvantages of Machine CodeAdvantages Disadvantages

Written Exercise 1

Page 9: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Advantages and Disadvantages of Machine CodeAdvantages

• Execute fast because no translation is needed

• Require less space and system resources

Disadvantages

• Difficult for humans to create• Difficult for humans to debug• Not portable

Written Exercise 1

Page 10: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

ASSEMBLY LANGUAGES

Page 11: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Assembly Languages

LDA B

ADD C

STA D

1101 110001

1101 111100

1000 111100

Arithmetic Logic Unit (ALU)

CPU

Control Unit (CU)

Instruction Register

Accumulator

Shift Register

Program Counter

Page 12: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

ASSEMBLY LANGUAGES

USE MNEMONICS

LDA BADDCSTA D

Page 13: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Assembly Languages are LLL

• Programs in Assembly are still difficult and long to write, but they are more English-Like than machine code

Page 14: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Opcode and OperandAddress Data001 LDA N1

010 ADD N2

011 ADD N3

100 STA ans101 STP110 (N1)111 (N2)1000 (N3)1001 (ans)

ADD N2Opcode

What to do

OperandWhat

data to use

Instruction

Page 15: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

ADDRESSING

Page 16: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Types of Addressing

• Symbolic addressing • LDA N1

• Direct addressing• LDA 110

• Immediate addressing• LDA # 9

Address Data

001 LDA N1

010 ADD N2

011 ADD N3

100 STA ans

101 STP

110 (N1) 9

111 (N2) 7

1000 (N3) 13

1001 (ans)

Page 17: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Types of AddressingAddress Data

001 LDA N1

010 ADD N2

011 ADD N3

100 STA ans

101 STP

110 (N1) 9

111 (N2) 7

1000 (N3) 13

1001 (ans)

What Type of Addressing is involved?

LDA N2

LDA 111

LDA # 7

Page 18: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Types of AddressingAddress Data

001 LDA N1

010 ADD N2

011 ADD N3

100 STA ans

101 STP

110 (N1) 9

111 (N2) 7

1000 (N3) 13

1001 (ans)

What Type of Addressing is involved?

LDA N2 Symbolic Addressing

LDA 111 Direct Addressing

LDA # 7 Immediate Addressing

Page 19: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

True or False

Answer

1. A Low Level Language is easier to code in and debug

2. Programs in a LLL will execute faster than equivalent HLL programs

3. Assembly Language is an LLL

4. Java is an LLL

5. LLLs are portable

6. Programming in an LLL requires a good knowledge of machine architecture

7. Programs in a LLL are less resource hungry than equivalent HLL programs

Page 20: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

True or False

Answer

1. A Low Level Language is easier to code in and debug False

2. Programs in a LLL will execute faster than equivalent HLL programs True

3. Assembly Language is an LLL True

4. Java is an LLL False

5. LLLs are portable False

6. Programming in an LLL requires a good knowledge of machine architecture True

7. Programs in a LLL are less resource-hungry than equivalent HLL programs True

Page 21: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

HIGH LEVEL LANGUAGES

Page 22: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

High Level Languages

Page 23: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Advantages and Disadvantages

Advantages

• More English-Like: easier to create and debug

• Portable

Disadvantages

• Require complex translation so may be slower to execute

• Programs in HLLs require more system resources

Page 24: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

GENERAL AND SPECIAL PURPOSE LANGUAGES

Page 25: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

General Purpose Language• A language that can be used to

develop applications in a number of field

Page 26: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

SPECIAL PURPOSE LANGUAGESA language developed specifically for creating programs with application in a

particular field.

Page 27: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Artificial Intelligence & Expert Systems

The study and design of

intelligent agents An intelligent agent is a system

that perceives its environment and

takes actions which maximizes its

chances of success

‘Deep Blue’ the first instance of AI, a computer chess game, managed to beat a human world champion at chess.

Page 28: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Artificial Intelligence & Expert Systems

An expert system can process large amounts of known information and provide conclusions based on them.

An expert system is a program that contains some of the subject-specific knowledge, and contains the knowledge and analytical skills of human experts.

Page 29: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Artificial Intelligence &

Expert Systems

• Most expert systems involve a program made up of a set of rules.

• The program analyses information about a specific class of problems, and provides mathematical analysis of the problem(s).

• Then, depending upon their design, they recommend a course of user action to implement corrections.

• The system utilizes what appear to be reasoning capabilities to reach conclusions.

Page 30: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

TRANSLATORS

Page 31: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Translating LLLs

• Translator from Assembly (LLL) to machine code

• Simple translation

Page 32: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

TRANSLATING HLLSBoth translate HLL to Machine Code (or LLL

Page 33: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Compilers & Interpreters

c = 0;

total = 0;

Repeat

Input num;

total = total + num;

c = c + 1;

Until c = 5;

Page 34: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Compilers

• It goes through the source code checking program structure

• once no errors are found it translates line by line, producing object code which can be saved and executed without requiring translation.

• In the case of a loop the section of code does NOT need to be translated each time the loop executes

Use:

• to translate programs for distribution: so the consumer only gets the object code

Page 35: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Interpreters

• Interpreters translate one line at a time and then execute it before moving on to translate the next line. No object code is created.

Use:

• While creating and testing a program

Page 36: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Tick as appropriateAssembler Interpreter Compiler

Translates LLL programs to Machine Code

Translates HLL programs

Translates the whole program before execution starts

Produces object code that can be saved and laterexecuted without further translation

Ideal for use during program development

Ideal for use when distributing software

Page 37: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Tick as appropriateAssembler Interpreter Compiler

Translates LLL programs to Machine Code

Translates HLL programs

Translates the whole program before execution starts

Produces object code that can be saved and laterexecuted without further translation

Ideal for use during program development

Ideal for use when distributing software

Page 38: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

SO WHAT’S SO GREAT ABOUT JAVA?

Page 39: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

So what’s so great about Java?

We need our code to be translated for many different platforms

Page 40: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

So what’s so great about Java?

Bytecode

Compiled

Interpreted

JVMJava Virtual Machine

Linux machine

iPhone

Windows PC

Java Source Code

Platform IndependentPlatform

Independent

Platform Dependent

Interpreted

Interpreted

Page 41: PROGRAMMING LANGUAGES€¦ · Computer languages are used to develop programs. ... This is a programming language that that provides little or noabstraction from a computer'sinstruction

Two-Step Translation

In Java translation is done in two steps: using first a compiler, then an interpreter.

The program is first compiled to produce bytecode. At this stage the user cannot view the actual code but the program is still platform independent. Therefore the bytecode is ideal for distribution.

Then the JVM on the machine the program will run on uses an interpreter to translate the program into executable code. The executable code is platform dependent because it will be different for a Linux Machine and a Windows PC etc.