Date: Wed, 11 Dec 1996 22:34:43 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Thu, 12 Sep 1996 16:47:34 GMT
Content-length: 5771
CS 302 Section 70 Lecture Notes - Week 1
Lecture Notes - Week 1
- Topic:
- Introduction to computers and programming. How to use Microsoft Windows and Microsoft FORTRAN on the Hewlett-Packard Vectra's
- Text:
- Chp. 1.1 - 1.5
- Notes:
-
Introduction to FORTRAN-77
Brief History
- One of the first high-level programming languages (circa 1957).
- FORula TRANslator. Good for engineering and scientific applications.
- FORTRAN-77 (1977 revision) is the standard and most widespread version. FORTRAN-90 (1990 revision) has additional functionality but is not as widespread.
Why learn FORTRAN instead of C++/Pascal/BASIC/...
- Easier to write complex formulas and equations.
- Still widely used in engineering.
- Lots of existing engineering program libraries are written in FORTRAN.
- Easy to learn, similar to BASIC.
How to use FORTRAN on the PC's
Click here
Compiling Steps
- Source Program (.for) in Fortran sent to compiler
- Compiler translates Fortran into "machine language with a couple of holes left",spits out .obj file
- A program may be broken into lots of segments, so there may be other obj's around. At any rate, .objs must be linked together plus some other things needed to "fill in those holes" (don't worry about what the holes are). .obj files all read in, spits out .exe file (runnable machine language).
Inside the Computer
- Input: Keyboard,Mouse
- Output: Monitor,Printer
- Inside:
- CPU: Central Processing Unit. What does computations.
- Memory: Where the data is (the program itself and its data)
- Removable storage. Can take things off disk onto memory or back. Must put things in memory in order to run it.
Memory and Binary (to the tune of "Ebony and Ivory"...just kidding)
- Each cell of memory (called a bit) either has a charge or has no charge. We call a charge 1 and no charge 0.
- 8 bits is one byte (a string of a combo of eight 0's and 1's). Since each bit can be one of 2 things, 2 bits can be one of 4 things (00,01,10,11),3 bits can be one of 8 things (000,001,010,011,100,101,110,111), i.e. 2^n. So a byte lets us store up to 2^8 = 256 different patterns.
- Binary counting:
- Decimal counts 0,1,2,3....9,10,11,....99,100,...999,1000
- Ones place, tens Place, Hundreds place (i.e. 10^0,10^1,10^2...). This is because each digit can be one of 10 things (just as binary in the example above uses powers of 2).
- So in binary, we have Ones place, two's place, four's place (i.e. 2^0,2^1,2^2...). Take 1101, for example. In Decimal, 1101 is 1x10^3 + 1x10^2 + 1x10^0. in BINARY, 1101 is 1x2^3 + 1x2^2 + 1x2^0 = 8+4+1 = 13.
Machine Language,Assembly,Fortran
- Dark Ages(1960): Since everything stored as 0's and 1's, everything is written that way. For example, 1101 might stand for "add". So 1101 0001 0011 0010 might mean "add whatever's in memory location 0001 to whatever's in 0011 and store the result in memory location 0010" (note the last three sets of digits refer to memory locations). You can't actually add to and from memory locations, so this is not quite a real example, but it gives you an idea of what's going on.
- Machine code is very hard to read. If you saw code like 1101 0001 0011 0010 1010 1111 1110 ... you'd go nuts. Esp. since "add" takes 3 arguments, "move" takes 2 arguments, etc, so hard to tell which sets of numbers stand for commands (like "add") and which stand for memory locations.
- Solution: Assembly language. ADD 0001 0011 0010. Every machine lang. statement corresponds to one assembly statement, and vice versa.
- Problem. Takes a loooong time to write out. You also have to worry about lots of details. Programmers noticed that many times there were sequences of steps that were repeated quite a lot, such as
LOAD 0001 %r1
LOAD 0011 %r2
ADD %r1 %r2 %r3
STORE %r3 0010
(Don't worry, you won't have to know this. This is just to show how tedious things were in Assembly Language). This says, take two memory locations and stick their values in registers. A register is a place where you do computations. It's separate from memory (CS354 explains how and why). So in order to compute you have to grab values from memory, stick them on registers, add the two registers into a third register, then store it back into memory somewhere else. WHEW!
- Instead, it'd be nice to just say SUM = TERM1 + TERM2. This is a Fortran statement which is translated (compiled) into those assembly instructions you see above. You don't have to worry about where in memory SUM,TERM1,and TERM2 are located...the compiler takes care of that for you. You don't have to worry about registers; again, the compiler does that. So four statements get compacted into one, and you don't even have to deal with binary!
Copyright © 1996 Modified fromJeff Lampert (tick@cs.wisc.edu). Last modified September 11, 1996