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

Post on 09-Jun-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PROGRAMMING LANGUAGES

Marlene Galea

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.

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.

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.

LOW LEVEL LANGUAGES

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

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.

Advantages and Disadvantages of Machine CodeAdvantages Disadvantages

Written Exercise 1

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

ASSEMBLY LANGUAGES

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

ASSEMBLY LANGUAGES

USE MNEMONICS

LDA BADDCSTA D

Assembly Languages are LLL

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

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

ADDRESSING

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)

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

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

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

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

HIGH LEVEL LANGUAGES

High Level Languages

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

GENERAL AND SPECIAL PURPOSE LANGUAGES

General Purpose Language• A language that can be used to

develop applications in a number of field

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

particular field.

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.

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.

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.

TRANSLATORS

Translating LLLs

• Translator from Assembly (LLL) to machine code

• Simple translation

TRANSLATING HLLSBoth translate HLL to Machine Code (or LLL

Compilers & Interpreters

c = 0;

total = 0;

Repeat

Input num;

total = total + num;

c = c + 1;

Until c = 5;

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

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

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

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

SO WHAT’S SO GREAT ABOUT JAVA?

So what’s so great about Java?

We need our code to be translated for many different platforms

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

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.

top related