machine languages it is the only language the computer understands. it is made of 0s and 1s. they...

27

Upload: daniel-griffin

Post on 13-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of
Page 2: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Machine Languages

• It is the only language the computer understands.

• It is made of 0s and 1s.• They must be in 0s and 1s because the

internal circuit of a computer is made up of switches, transistors, and other electronic devices that can be either on or off (1 or 0 respectively). Example of Machine Language: (on page167)

1 0000000000000100 0000000000000000

2 0101111000001100 110000100000000000000010

3 1110111100010110 0000000000000101

Page 3: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Symbolic Languages

• Developed by Grace Hopper, a mathematician for US Navy in 1950s

• It uses symbols or mnemonics to represent machine language

• A program called an assembler is used to translate symbolic code into machine language

• They’re also known as assembly languages because they have to be assembled

Page 4: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Symbolic Languages Cont’d.Example: multiplication program page 168

1 entry main, ^m<r2>

2 sub12 #12, sp

3 jsb C$MAIN_ARGS

4 movab $CHAR_STRING_CON

5

6 pushal -8(fp)

7 pusal (r2)

8 calls #2, read

9 pushal -12 (fp)

10 pushal 3 (r2)

11 calls #2, read

12 mull3 -8 (fp), -12 (fp), -

13pusha 6 (r2)

14 calls #2, print

15 clrl r0

16 ret

Page 5: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

High-Level Languages

• Developed to improve programmer efficiency from symbolic languages & to change focus from the computer to the problem being solved

• They’re portable to different computers• They still need to be converted to machine languages in

a process called compilation• Examples include:

– BASIC– COBOL– Pascal– Ada– C

Page 6: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Natural Languages

• These include the language that people speak in their daily lives

• These can include:– English– Spanish– German– French– Italian

• The idea is to use one’s natural language to give the computer orders

• This has only limited use today

Page 7: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Building a Program

1. Writing and Editing Programs:• Use a text Editor to write programs• When you’re done you save your program to the disk (known as a source file)

and it will be input to the compiler2. Compiling Programs:

• Translates inf in a source file into machine language• Made of 2 separate programs: the preprocessor & the translator• Preprocessor: reads the source code and prepares it for the translator. While

preparing the code it scans for special commands (preprocessor directives) that tell it to look for special code libraries, make substitution in the code, & other ways to prepare the code for translation into machine language. The result of this processing is called the translation unit.

• Translator: converts the translation unit into machine language. This code in machine language is called the object module

3. Linking Programs:• A high-level language has many subprograms, some of which are written in the

program & some exist elsewhere and have to be attached to the program (ex: I/O processes)

• The linker assembles all of these functions into the final executable function.

Page 8: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Program Execution

• Use the Operating System (OS) command (ex.: run) to load the program into primary memory & execute it.

• Loader: it is an OS program responsible for loading the program into the memory

• Program reads data for processing either from the user or from a file

• After the program processes the data it prepares the output to either the monitor or to a file

• When the program is finished it tells the OS, which removes the program from memory

Page 9: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Categories of Languages

Procedural (Imperative) Languages Object Oriented Languages Functional Languages Declarative (Logic) Languages Special Languages

Categories of Langauges

Page 10: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Procedural (Imperative) Languages

• Procedural Language: a set of instructions that are executed one-by-one from beginning to end unless an instruction forces the control elsewhere

• Each instruction either manipulates data items or is a control execution.

• Examples: – FORTRAN– COBOL– Pascal– C– Ada

Page 11: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

FORTRAN

• FORmula TRANslation• Designed by a group of

IBM engineers & was commercially available in 1957

• First high-level language• Features:

– High-precision arithmetic

– Capability of handling complex numbers

– Exponentiation computation (ab)

Page 12: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

COBOL

• COmmon Business-Oriented Language

• Designed by US Navy computer scientists

• Designed to be used as a business programming language

• Fast access to files and databases

• Fast updating of files and databases

• Large amounts of generated reports

• User-friendly formatted output

Page 13: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Pascal

• Invented by Nikalus Wirth in 1971 in Zurich, Switzerland

• Named after Blaise Pascal, the 17th century French mathematician & philosopher who invented the Pascaline calculator

• Designed to teach programming to novices by emphasizing the structured programming approach

Page 14: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

C & Ada

• C language developed by Dennis Ritchie at Bell Laboratories

• Originally designed for writing Operating Systems

• Later became popular among programmers

• Ada was named after Augusta Ada Byron, the daughter of Lord Byron & the assistant to Charles Babbage

• Created by US Department of Defense to be a uniform language used by all Department of Defense contractors

Page 15: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Object-Oriented Languages

• The objects (a data item) & the operations to be applied to them are tied together

• Programmer first defines and object & the types of operations that can be applied to this object & can use this combination & invokes some or all of the operations defined to solve a problem

• The objects are active• Example:

– C++– Java

Page 16: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

C++

• Developed by Bjarne Stroustrup at Bell Laboratories

• Uses classes to define general characteristics of similar objects & the operations that can be applied to them

• 3 principles: encapsulation, inheritance, polymorphism

• Encapsulation: the idea of hiding the data & some operations that can be performed on the data inside the object

• Inheritance: an object can inherit from another object

• Polymorphism: you can define several operations with the same name that can do different things in related classes

Page 17: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Java

• Developed by Sun Microsystems, Inc.

• Based on C & C++• It’s totally class oriented• Program can be either an

application or an applet• Application: stand-alone

program• Applet: embedded in HTM

language, stored on a server, & run by a browser

• Class Library: a collection of classes

• Multithreading: a thread is a sequence of actions executed one after the other, Java allows for multithreading

Page 18: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Functional Languages

• A program is considered a mathematical function• A function is a black box that maps a list of inputs to a list of outputs• It does the following:

– It predefines a set of primitive (atomic) functions that can be used by any programmer

– It allows the programmer to combine primitive functions to create new functions

• Advantages over procedural language:– It encourages modular programming– Allows the programmer to make new functions our of existing ones

• Examples:– LISP– Scheme

Page 19: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

LISP & Scheme

• LISt Programming• Designed by researchers

at MIT in the early 1960s• Everything is considered

a list

• Scheme• Version of LISP

developed by MIT in 1970s

• Defines a set of primitive functions that solves problems

Page 20: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Declarative (Logic) Languages

• Uses the principle of logical reasoning to answer queries

• Based on formal logic defined by Greek mathematicians & later developed into what is called first-order predicate calculus

• Logical reason is based on deduction• One problem: a program is specific to a

particular domain because collecting all the facts into one programming makes it huge

• Example:– Prolog

Page 21: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Prolog

• PROgramming in LOGic

• Developed by A. Colmerauer in France in 1972

• Program is made of facts and rules

Page 22: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Special Languages

• HTML

• PERL

• SQL

Page 23: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

HTML

• Hypertext Markup Language• Pseudolanguage that includes marks that serve as formatting hints &

links & tags• HTML file is made of texts & tags• Tag:enclosed in 2 angle brackets & usually come in pairs; marks that are

embedded into the text; it can have a list of attributes , each of which can be followed by an equal sign & value associated with the attribute

• HTML file (page) is stored on the server & can be downloaded by a browser

• Browser removes the tags & interprets them as either formatting hints or links to other files

• Allows you to embed formatting instructions in the file itself & are stored in the text

• 2 parts:– Head: the first part that contains the title of the page & other parameters that

the browser will used– Body: the actual contents of a page; includes the text & tags; text is the actual

info contained in a page; tags define the appearance of the page

Page 24: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

HTML

Page 25: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

PERL

• Practical Extraction & Report Language

• High-level language with a syntax similar to the C language but more efficient

• Its power is in its well-designed use of regular expressions that allow the programmer to parse a string of characters into its components & extract the needed info

Page 26: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

SQL

• Structured Query Language

• Used to answer queries about databases

Page 27: Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of

Overview

• Types of languages:– Machine, Symbolic, High-Level, Natural

• Building a program:– Writing & editing– Compiling– Linking

• Categories of Languages:– Procedural (ex: FORTRAN)– Object-Oriented (ex: C++)– Functional (ex: LISP)– Declarative (ex: Prolog)– Special (ex: HTML)