0% found this document useful (0 votes)
18 views33 pages

Intro Fortran 1

Uploaded by

ensiliyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views33 pages

Intro Fortran 1

Uploaded by

ensiliyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Ahmadu Bello University, Zaria, Nigeria

Department of Computer Science

COSC 202- Computer Programming Using


Fortran

Department of Computer Science, ABU, Zaria Programming In Fortran 1


Introduction to Computer Systems
 Lecture Objectives:
 The student should be able to identify and explain the major components of a computer system
in terms of their functions.

 What is a Computer?

 Anatomy of a Computer System

 Computer Software

 Computer Hardware

 Fetch-Decode-Execute Cycle

 CPU Families

 Exercises

Department of Computer Science, ABU, Zaria Programming In Fortran 2


What is a Computer System?
 A computer system is an electronic device which can input, process, and
output data

input processing output

memory

 Input data of a computer may represent numbers, words, pictures etc

 Programs that control the operations of the computer are stored inside the
computer

Department of Computer Science, ABU, Zaria Programming In Fortran 3


Major Components of a Computer System
 A computer system consists of two main parts: hardware and software

 Hardware is the physical components and software is the non-


physical components of a computer system.

 Computer hardware is divided into three major components:


 1. Input/Output (I/O) devices
 2. Computer memory
 3. The Central Processing Unit (CPU)

 Computer software is divided into two main categories:


 1. Systems software
 2. Applications software

Department of Computer Science, ABU, Zaria Programming In Fortran 4


Systems Software
 System software manages computer resources and makes computers easier to
use

 Systems software can be divided into three categories:

1. Operating System (OS)


 Examples: Windows XP, UNIX and MacOS

2. System support software


 Examples: disk-formatting and anti-virus programs.

3. System development software.


 Example: Language translators.

Department of Computer Science, ABU, Zaria Programming In Fortran 5


Applications Software
 An applications software enables a computer user to do a particular
task

 Example applications software include:

 Word processors

 Game programs

 Spreadsheets (or Excel sheets)

 Database systems

 Graphics programs

 Multimedia
Department of Computer applications
Science, ABU, Zaria Programming In Fortran 6
Computer Hardware

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 7


I/O (Input/Output)Devices
 Input devices are used to enter programs and data into a computer system.
 Examples: keyboard, mouse, microphone, and scanner.

 Output devices are where program output is shown or is sent.


 Examples: monitor, printer, and speaker.

 I/O devices are slow compared to the speed of the processor.


 Computer memory is faster than I/O devices: speed of input from memory to processor
is acceptable.

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 8


Computer Memory
 The main function of computer memory is to store software.

 Computer memory is divided into primary memory secondary


and
memory.
 Primary memory is divided into random access memory (RAM) and read-
only memory (ROM):

 The CPU can read and write to RAM but the CPU can read from ROM but cannot write to
ROM

 RAM is volatile while ROM is not.


 Secondary memory
 Examples of secondary memory devices are: hard disks, floppy disks and CD ROMs

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 9


Primary Memory

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 10


The CPU
 The CPU is the "brain" of the computer system.
 The CPU directly or indirectly controls all the other components.

 The CPU has a limited storage capacity.


 Thus, the CPU must rely on other components for storage.

 The CPU consists of:


 1. The Arithmetic and Logic Unit (ALU).
 2. The Control Unit (CU).
 3. Registers.

 The CPU components are connected by a group of electrical wires called the
CPU bus.

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 11


The CPU (cont’d)

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 12


Fetch Decode Execute Cycle
 The CPU continuously transfers data to and from memory

 Data transfer is done in units called instructions or words

 When a computer is switched on, the CPU continuously goes


through a process called fetch-decode-execute cycle:

 The Control Unit fetches the current instruction from memory, decodes it and instructs the ALU to execute
the instruction.

 The execution of an instruction may generate further data fetches from memory

 The result of executing an instruction is stored in either a register or RAM

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 13


Fetch-Decode-Execute Cycle (cont’d)

Instruction
Cycle
Main Memory
1 Control Unit
Fetch 2 Decode

cpu

RAM
Execution
Cycle
Execute
Store 3
4

Arithmetic/Logic Unit

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 14


CPU Families
 Different people understand different natural languages.

 Similarly, each processor family understands its own machine language.

 The fundamental difference between computers that are not compatible is


in their processors.

 Here are some CPU families:


 Pentium
 Power PC
 SPARC

 The question now is: Is it possible to write a single program that can be
understood and correctly executed on machines with different processors?
 We’ll address this question in a subsequent lecture.
Department of Computer Science, ABU, Zaria Object-Oriented Programming I 15
Drill Questions

1. Write short notes explaining the functions of each of the following


1. Computer memory
2. The CPU
3. Computer software
2. I/O devices can be used to input into and output from a computer
system. Then, is computer memory necessary? Explain.
3. Since the OS controls the hardware and software in a computer
system, which programs control the loading of an OS onto a computer
system?
4. The system bus consists of three buses. Mention them and explain
each of
them briefly.
5. Since different CPUs understand different instructions, how are we able to
exchange information between machines with different CPUs?
Department of Computer Science, ABU, Zaria Object-Oriented Programming I 16
Overview of Programming
 LectureParadigms
Objectives:
 Be able to explain the differences between programming languages and programming paradigms.
 Be able to differentiate between low-level and high-level programming languages and their
associated advantages and disadvantages
 Be able to list four programming paradigms and describe their strengths and weaknesses.

 Introduction to Computer Programming


 Programming Languages
 Programming Paradigms
 Exercises

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 17


Computer Programming
 The functions of a computer system are controlled by computer programs
 A computer program is a clear, step-by-step, finite set of instructions

 A computer program must be clear so that only one meaning can be derived from it,

 A computer program is written in a computer language called a programming


language

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 18


Programming Languages
 There are three categories of programming languages:

 1. Machine languages.

 2. Assembly languages.

 3. High-level languages.

 Machine languages and assembly languages are also called low-level languages

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 19


Programming Languages (cont’d)
 A Machine language program consists of a sequence of zeros and ones.
 Each kind of CPU has its own machine language.
 Advantages
 Fast and efficient

 Machine friendly

 No translation required

 Disadvantages
 Not portable

 Not programmer friendly

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 20


Assembly Language
 Assembly language programs use mnemonics to represent machine instructions

 Each statement in assembly language corresponds to one statement in machine language.

 Assembly language programs have the same advantages and disadvantages as machine
language programs.

 Compare the following machine language and assembly language programs:

8086 Machine language program for 8086 Assembly program for


var1 = var1 + var2 ; var1 = var1 + var2 ;
1010 0001 0000 0000 0000 0000 MOV AX , var1
0000 0011 0000 0110 0000 0000 0000 0010 ADD AX , var2
1010 0011 0000 0000 0000 0000 MOV var1 , AX

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 21


High-Level Programming Languages
 A high-level language (HLL) has two primary components
 (1) a set of built-in language primitives and grammatical rules
 (2) a translator

 A HLL language program consists of English-like statements that are governed by


a strict syntax.

 Advantages
 Portable or machine independent
 Programmer-friendly

 Disadvantages
 Not as efficient as low-level languages
 Need to be translated

 Examples : C, C++, Java, FORTRAN, Visual Basic, and Delphi.

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 22


Programming Paradigms
 Why are there hundreds of programming languages in use today?
 Some programming languages are specifically designed for use in certain applications.
 Different programming languages follow different approaches to solving programming problems

 A programming paradigm is an approach to solving programming problems.

 A programming paradigm may consist of many programming languages.

 Common programming paradigms:


 Imperative or Procedural Programming
 Object-Oriented Programming
 Functional Programming
 Logic Programming

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 23


Programming Paradigms: Imperative
 In this paradigm, a program is a series of statements containing variables.

 Program execution involves changing the memory contents of the computer


continuously.

 Example of imperative languages are: C, FORTRAN, Pascal, COBOL etc

 Advantages
 Low memory utilization
 Relatively efficient
 The most common form of programming in use today.

 Disadvantages
 Difficulty of reasoning about programs
 Difficulty of parallelization.
 Tend to be relatively low level.

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 24


Programming Paradigms: Object-Oriented
 A program in this paradigm consists of objects which communicate with each other by
sending messages

 Example object oriented languages include: Java, C#, Smalltalk, etc

 Advantages
 Conceptual simplicity
 Models computation better
 Increased productivity.

 Disadvantages
 Can have a steep learning curve, initially
 Doing I/O can be cumbersome

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 25


Programming Paradigms: Functional
 A program in this paradigm consists of functions and uses functions in a similar way as
used in mathematics
 Program execution involves functions calling each other and returning results.
There
are no variables in functional languages.

 Example functional languages include: ML, MirandaTM, Haskell

 Advantages
 Small and clean syntax
 Better support for reasoning about programs
 They allow functions to be treated as any other data values.
 They support programming at a relatively higher level than the imperative languages

 Disadvantages
 Difficulty of doing input-output
 Functional languages use more storage space than their imperative cousins
Department of Computer Science, ABU, Zaria Object-Oriented Programming I 26
Programming Paradigms: Logic
 A program in the logic paradigm consists of a set of predicates and rules of inference.
 Predicates are statements of fact like the statement that says: water is wet.

 Rules of inference are statements like: If X is human then X is mortal.


 The predicates and the rules of inference are used to prove statements that the programmer
supplies.

 Example: Prolog

 Advantages
 Good support for reasoning about programs
 Can lead to concise solutions to problems

 Disadvantages
 Slow execution
 Limited view of the world
 That means the system does not know about facts that are not its predicates and rules of inference.
 Difficulties in understanding and debugging large programs

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 27


Which Programming Paradigm is
 Which of these paradigms is the best?
Best?
 The most accurate answer is that there is no best paradigm.

 No single paradigm will fit all problems well.

 Human beings use a combination of the models represented by these


paradigms.

 Languages with features from different paradigms are often too complex.

 So, the search of the ultimate programming language continues!

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 28


Review Questions
1. List two advantages and two disadvantages of low-level languages.

2. Explain the similarities and differences between an assembly language and


a machine language.

3. Mention the programming paradigm to which each of the following


languages belongs: Visual Basic, Java, C#, Haskell, Lisp, Prolog,
Pascal.

4. Which programming paradigms give better support for reasoning


about programs?

5. Which programming paradigms give better support for doing I/O?

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 29


Programming Languages Translation
 Lecture Objectives:
 Be able to list and explain five features of the Java programming language.
 Be able to explain the three standard language translation techniques.
 Be able to describe the process of translating high-level languages.
 Understand the concept of virtual machines and how Java uses this concept to achieve
platform independence.
 Understand the structure of simple Java programs

 Java Programming Language


 Translating High-level Languages
 The Java Virtual Machine
 Java Program Structure
 Exercises

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 30


The Java Programming Language
 The object-oriented paradigm is becoming increasingly popular compared to other paradigms.

 The Java programming language is perhaps the most popular object-oriented language today.

 Here are some reasons why Java is popular:


 1. Simple.
 Compared to many modern languages, the core of the Java language is simple to master.
 2. Object-oriented.
 Java is an object-oriented language and therefore it has all the benefits of OO languages
described earlier.
 3. Secure.
 The Java system controls what parts of your computer a program access.
 4. Architecture neutral.
 A Java program will run identically on every platform. We will explain how
Java achieves this portability later in this session.
 5. Java is for Internet applications
 Java was designed so that it can download programs over the Internet and execute them.

Department of Computer Science, ABU, Zaria Object-Oriented Programming I 31


High Level Language Translators
 As mentioned earlier, one of the disadvantages of a high-level language is that it must
be translated to machine language.

 High-level languages are translated using language translators.

 A language translator is that translates a high-level language program or an


assembly language program into a machine language program.

 There are three types of translators:


 1. Assemblers.
 2. Compilers.
 3. Interpreters.

Department of Computer Science, ABU, Zaria Programming In Fortran 32


High Level Language Translators
 Assemblers
 An assembler is a program that translates an assembly language program, written in a
particular assembly language, into a particular machine language.
 Compilers
 A compiler is a program that translates a high-level language program, written in a
particular high-level language, into a particular machine language.
 Interpreters
 An interpreter is a program that translates a high-level language
program, one instruction at a time, into machine language.
 As each instruction is translated it is immediately executed.
 Interpreted programs are generally slower than compiled programs because compiled
programs can be optimized to get faster execution.
 Note that:
 Some high-level languages are compiled while others are interpreted.
 There are also languages, like Java, which are first complied and then interpreted

Department of Computer Science, ABU, Zaria Programming In Fortran 33

You might also like