This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Chapter 2 The Baby Steps Computers can do arithmetic, logical operation, storing and retrieving data, and communicate with users via its input/output ports. A program is needed to coordi- nate these elementary operations so that useful tasks can be performed. A program is then a list of directions that tells the machine what operation to perform next. In procedural languages such as FORTRAN, the directions are executed one at a time in the order they are encountered. 2.1 The notorious “Hello World” A very simple program to get us started is listed below, the textbook lists in the F77 version and here it is in its F90 glory: ! Anything after an exclamation mark is a comment ! This is a simple code program hello_world ! start and name of program, optional in F77 print *,’Hello World!’ ! print command stop ! program terminates end program hello_world ! end of program , F77 accepts "end" only The programs simply prints the sentence ”Hello World!” and stops. Here are some remarks about the code: • The program is just text entered with an editor such as emacs. The text is referred to as source code. • Any text after an exclamation mark is a comment and is not processed by the compiler. It is there for documentation purposes. The fixed • The other lines of codes are FORTRAN statements . Some of them, such as print and stop are executable statements in that they direct the computer to do something such as print or stop the program and return control to the 11 12 CHAPTER 2. THE BABY STEPS operating system. Other statements, such as program and end program are non-executable and are needed by the compiler to process the source code. • Each line not beginning with a comment sign is a statement. The end of a line denotes the end of a statement unless the line is continued with a continuation sign; in F90 that is a & sign at the end of the line. Comment lines cannot be continued and must start with a comment sign. • The text shown has been entered in free-form as opposed to the fixed form required by F77. The old dialect required that the first 6 spaces be reserved for statement labels (the first 5 columns), for a continuation character (the 6 th column). The line also had to end on column 72. • The F77 standard required that all characters be capitalized. Many compiler permitted lower case characters, however, the requirement has been dropped since the F90 revision to the standard. • The Stop statement causes the program to terminate and control is handed back to the operating system. • The print statement causes the string constant “Hello World!” to be printed. The * instructs the compiler to use default formatting to print the string....
View Full Document
- Fall '08
- Assembly Language