ENGR2216 FORTRAN PROGRAMMING FOR ENGINEERS Chapter 1 The computer DATA REPRESENTATION CPU MEMORY INPUT/OUTPUT DEVICES BINARY SYSTEM OCTAL & HEXADECIMAL DATA TYPES HISTORY OF FORTRAN EVOLUTION OF FORTRAN Computers: are they important? Solving problems in any field Can you imagine a computer without software (programmes)? Computer’s success is tied to programming Where do we find computers? In a grocery store: scanners checking prices ATM (Automatic Teller Machines) Mobiles Microwave oven Cars Do you believe that the first electronic computer was invented about 60 years ago? Basic Definitions A computer: is a special type of machine that stores information and can perform mathematical calculations on that information at speeds much faster than human beings can think. A program: tells the computer what sequence of calculations are required and on which information to perform the calculations. Examples of Programmes A computer at the bank stores customers’ information. Another programme can check each customer’s account daily. Once it goes below 100 Rials, the customer gets charged 1 Rial. Another programme can monitor the customers’ account, and send an sms message to the customers informing them that it’s time to take out their Zakat. Another program: when your phone’s battery becomes low, it gives you a warning: ”low battery”. Computers vs. Human Are computers smarter than human? No, they only process programmes faster. They follow the instructions given in a programme. They can’t think on their own. They must be told what to do and when to do it A clever programme means a clever programmer The computer CPU = computer’s heart Main memory CPU = Control + ALU + memory Control: controls all PC parts ALU: performs calculations Memory: temporary storage of results during calculations Control: Interpret instructions Fetch data from input Send data from memory to output devices or main memory E.g. multiply 2 × 3 Secondary memory Internal Memory (registers) Input devices Control unit Arithmetic Logic unit Central Processing Unit Output devices The computer Main memory (e.g. RAM) Primary Volatile Semiconductor chip Very fast Fetch time 60 ns Expensive Store currently used programme Secondary memory (e.g. HDD) Non-volatile … explain! Higher capacity (80GB vs. 1GB) Slower Cheaper Main memory Secondary memory Internal Memory (registers) Input devices Control unit Arithmetic Logic unit Central Processing Unit Output devices The computer Input devices Main memory Purpose: enter data/information Examples: Keyboard Mouse Scanner Camera microphone Secondary memory Internal Memory (registers) Input devices Control unit Output devices Purpose: display results Examples: Monitors/ LCDs Printers Plotters speakers Arithmetic Logic unit Central Processing Unit Output devices The binary number system (725)10 = 7 × 102 + 2 × 101 + 5 × 100 (101)2 = 1 × 22 + 0 × 21 + 1 × 20 Used by human Used by computers Examples: Find the following: (111)2 (011)2 (00001110)2 = (……)10 = (……)10 = (……)10 Byte = 8 bits How many possible values can we make with a 3-bit binary number? Hint: (000) to (111) HOW TO CONVERT FROM BASE 10 TO BASE 2? The 2n rule. Data representation in a computer What is a computer memory composed of ? Millions of ON/OFF switches How does a PC store data in memory? A switch is either ON (1) or OFF (0) A single switch can represent only 1 or 0. What does bit mean? BIT stands for Binary Digit A bit is either 1 or 0. 1 Byte = 8 bits representing a binary number E.g. memory of 256 MB (megabytes) = 256 million bytes E.g. hard disk drive with storage of 40 gigabytes = 40 billion bytes 1 word = 2, 4, (or more) consecutive bytes = 32, 64, bits How many possible values can we make with 1 byte? 28 = 256 possible values (-128 to 127) Binary (2), Octal (8) and Hexadecimal (16) Decimal Binary Octal Hexadecimal 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F Types of Data stored in memory 1. Each type needs a different amount of memory Character Data: UPPER CASE LETTERS (A-Z) = 26 Lower case letters (a – z) = 26 Digits (0 – 9) = 10 Symbols: “ , ( ) [ ] ! ~ @ # $ % ^ & * . Special letters or symbols (e.g. é) Total number < 256 1 byte per character 1,000 characters need 1,000 bytes For non-English languages, more characters are used) Task: read text book for 2. 3. ASCII coding and EBCDIC coding Integer Data Real Data (floating point) Types of Data stored in memory 1. 2. Each type needs a different amount of memory Character Data Integer Data: -ve integers, +ve integers, and zero Needs 1, 2, 4, or 8 bytes (differs from one computer type to another) In any computer that uses n-bit integer: What happens if a larger number is used? 3. Smallest integer = -2n-1 Largest integer = 2n-1 – 1 (why -1?) Task: read text book Error: Overflow condition Real Data (floating point) Types of Data stored in memory 1. 2. 3. Each type needs a different amount of memory Character Data Integer Data Real Data (floating point): Used for fractional numbers (e.g. 0.25) Used for very large or very small integers Value = mantissa × 2exponent E.g. speed of light in decimal system = 2.998 × 108 m/s Computers use base 2 system, with 32 bits (4 bytes) of computer memory: 24 bits for mantissa 8 bits for exponent Task: read text book Precision Range Round-off error Computer Languages Machine language A program is a list of operations to be executed by a computer: A set of op codes is called machine language E.g. add 3,4 1011 0011 0100 store A 0101 0000 1010 Machine language is very hard for human High level languages: E.g. load, store, add, subtract, etc. Each operation has a binary pattern (e.g. add = 1011) called op code The data associated with the op code are called operands Easy to write/understand List of instructions Convert to machine language using compilers and linkers Examples of high level programming languages: Basic C++ COBOL Fortran Java FORTRAN Language Grandfather of all scientific computer languages FORmula TRANslation Translate formula into a computer code First FORTRAN: 1954 – 1957 By IBM for 704 computers FORTRAN Language Grandfather of all scientific computer languages FORmula TRANslation Translate formula into a computer code First FORTRAN: 1954 By IBM for 704 computers Integers and real data types only No subroutines FORTRAN II: 1958 FORTRAN IV: 1962 (stayed for 15 Years) FORTRAN IV: 1966 (adopted as ANSI standard, and called FORTRAN 66 FORTRAN 77: 1977 (introduced IF statements, and simplified using characters) Fortran 90: 1992 Fortran 95: 1996 Text book covers both 90/95 Task: Read sections 1.4, and 1.5 of the text book

Descargar
# ENGR2216 FORTRAN PROGRAMMING FOR ENGINEERS