home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
fortran
/
compiler
/
sbm
/
sbm.ls2
< prev
next >
Wrap
Text File
|
1991-01-10
|
22KB
|
621 lines
CONTENTS
Introduction to SBM fortran. . . . . . . . . . . . . . . . . . . . iii
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
Current status . . . . . . . . . . . . . . . . . . . . . . . . . . v
Fortran statements . . . . . . . . . . . . . . . . . . . . . . . . 1-1
Statement lables . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
Symbolic names and keywords . . . . . . . . . . . . . . . . . . . 1-1
Statement order . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Byte, Character, Integer*1, Logical . . . . . . . . . . . 1-3
Word, Integer, Integer*2 . . . . . . . . . . . . . . . . 1-3
Doubleword, Integer*4 . . . . . . . . . . . . . . . . . . 1-3
Character strings, ASCIIZ . . . . . . . . . . . . . . . . 1-3
Quoted strings . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Data declaration and initialization . . . . . . . . . . . . . . . 1-5
Data statement . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
UNIT (5-255). . . . . . . . . . . . . . . . . . . . . . . 2-1
IOCB names . . . . . . . . . . . . . . . . . . . . . . . 2-1
FILE . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
ALIAS (alternate name for io unit). . . . . . . . . . . . 2-1
STATUS (old, new, append) . . . . . . . . . . . . . . . . 2-1
RECL . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
READ STATEMENTS . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Unformatted . . . . . . . . . . . . . . . . . . . . . . . . 2-3
formatted . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
List directed . . . . . . . . . . . . . . . . . . . . . . . 2-4
Next character from keyboard (NEXCHAR). . . . . . . . . . . 2-4
WRITE STATEMENTS . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Unformatted . . . . . . . . . . . . . . . . . . . . . . . . 2-5
formatted . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
List directed . . . . . . . . . . . . . . . . . . . . . . . 2-6
SHOW_CHAR (display a character on screen) . . . . . . . . . 2-6
CRLF (write cr,lf to specified IOCB) . . . . . . . . . . . 2-6
FORMAT STATEMENTS . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Field and edit descriptors. . . . . . . . . . . . . . . . . 2-7
ARITHMETIC EXPRESSIONS . . . . . . . . . . . . . . . . . . . . . . 3-1
INC, DEC (incrementing and decrementing variables. . . . . 3-1
ADD, SUB (adding to, or subtracting from variables . . . . 3-1
Subscripts . . . . . . . . . . . . . . . . . . . . . . . . 3-2
INTRODUCTION TO SBM FORTRAN
This manual describes SBM FORTRAN. SBM is based on American National
Standards Institute FORTRAN 77 language. It is assumed that the reader
has knowledge of an existing FORTRAN language and is familiar with MSDOS
or PCDOS operating system. This manual is not intended to teach
FORTRAN, but is intended to be used as reference material only.
The original intention of SBM fortran was the author's answer to the 'C'
language. The cryptic nature of 'C', while appealing to many
programmers, leaves me cold. While I fully appreciate the power of the
'C' language (as with assembler), I felt that there was needed something
that would better suit my style.
I also remember when I brought my first XT home. There were many
fortran-written utilities that I had on the Z-80 without which I felt
very helpless. By the time I had rounded up the money to buy the system,
I had none left for the software that I very sorely needed. An
affordable compiler of an easily learned language seemed to the the
answer. A good reason for someone, such as I, to write SBM fortran.
The powerful fortran systems that are now on the market are designed with
the high-level user in mind. Program size is not important. I needed
something that would generate about the same code as if I wrote the it in
assembler.
This compiler operates by converting FORTRAN source code into assembler
instructions, which are then converted into machine code using WASM, an
assembler written by ERIC TAUK, of Merengo, IL. The result is a COM
file, which can then be run on any MSDOS based system.
THIS IS VERSION 1.00. To most of us this means a system that works well
enough for the author, but sometimes awkward for the user. Here is a
problem. I am in the process of moving to Wyoming. Here in Denver, I
have access to many excellent bulletin boards. In Wyoming, that will
not be the case. I must therefore release this version knowing that
there may be bugs. Since I will no longer have easy access to the
boards, I will not longer have easy access to you, the user. I must
therefore go to a 'shareware' mode.
To provide this connection, You must send me your name and mailing
address. That will make you a registered user. To receive ANY updates of
this compiler, you MUST be a registered user. At a minimum, I will
upgrade to provide some of the functions that I need. Registered users
will receive the first (or most recent) update. I most certainly need
your suggestions for improvements and bug removal. If you like this
compiler as I believe you will, your $20 contribution will be
appreciated. Since I will no longer have access to the boards, that's
the only way that you can receive the update.
MSDOS is a registered trademark of Microsoft Corporation.
PCDOS is a registered trademark of IBM Corporation.
iii
CURRENT STATUS OF SBM FORTRAN
BE VERY CAUTIOUS USING ANY SORTWARE! Do not trust it! Even if you
have been using it for awhile, mentally EDIT the output. Does it look
reasonable? You are the best judge.
SBM fortran is not a scientific compiler. i.e., it does not have
floating point.
Integer*4 is there, but needs more hooks before it can be used.
Arithmetic expressions are primitive, but gramatically correct and
transportable. This feature will be upgraded to some extent.
Needs more diagnostic messages. SBM fortran is not just forgiving. It's
actually permissive.
But, on the other hand, if you accept the above limitations, and write a
program using standard fortran coding techniques, it will work, and the
code can be put up and run under most other F77 compilers, without
modification.
FUTURE OF SBM FORTRAN
SBM fortran was not, and is not intended to be a full-blown fortran
compiler. It is not intended to compete with the more powerful
systems.
Integer*4 is one feature that will certainly be implememted. With large
integers, you can do quite a lot. Accounting work and other related
types of work require precise calculations. Large integers makes that
precision possible. Instead of dollars and cents, you can carry
everything in total cents. i.e. $156.25 is 15625 cents. For output,
the format statement can direct that a decimal point be inserted (this
feature is already installed, but not yet usable).
The compiler needs compile time and runtime error detection that it does
not now have. Some errors simply lock up the system. That is something
that must be addressed in the first update.
The direction of its future is mostly up to you. I have some floating-
point routines that could be implemented, but I will probably not work in
that direction unless there's enough response. The routines are in
another fortran compiler of mine which I chose not to release at this
time.
There's another feature, TONTO (trace-on, trace_off), that might also be
moved from my other compiler.
v
1-2
COMMENTS - You can use a semi-colon(;), an asterisk(*) or hyphen (-) in
column 1 to specify that the line is a comment. In addition, if you place
a ';' anywhere in the statement portion of a source line, the rest of
that statement will be treated as a comment. A blank line is also
considered to be a comment.
Individual assembler code statements can be inserted anywhere by placing
a plus (+) in column 1.
INCLUDE
Blocks of fortran statements, assembler code, and macros may be inserted
using the INCLUDE option.
Syntax: INCLUDE pathname Pathname can name any file that is
currently on line, on any disk.
To include assembler code or macros, the statement must have a '+' in
column 1 and the pathname must be in quotes.
Example: + include 'maclib.asm'
A small macro library is provided to generate some of the code that the
compiler needs. You may build one of your own choosing and insert it
using the + INCLUDE option.
1-4
QUOTED STRINGS
Over the years, we programmers have created a standard that would not be
acceptable to people other than programmers. That is, calling an
apostrophy a quote! When we think of quoted strings, we think of an ascii
string enclosed in apostrophies, not quotes. Don't know how this started,
but we all do it. Anyway, format statements sometimes require us to
specify a 'quoted' string for output. With this in mind, in this manual,
when we talk of a quoted string, we mean a string that is enclosed in
apostrophies.
When entering a quoted string that we wish wish to contain an imbedded
quote, SBM FORTRAN requires that you use an ACTUAL quote("). Standard
fortran wants you to use two apostrophies in a row. We do it differently
here.
example: standard fortran requires:
FORMAT('We sometimes don''t follow standards')
We do it this way:
FORMAT('We sometimes don"t follow standards')
2-2
READ STATEMENTS
READ statements transfer data from a specified I/O unit to memory. You
can reference both external and internal files. The input data may be
any ASCII stream.
Syntax: READ(UNIT [,FMAT]) list
UNIT is one of:
(1) An integer constant in the range of 5 to 255 that identifies an
external unit previously referenced in an OPEN statement.
(2) An asterisk (*) specifying the default I/O unit (console).
May be redirected.
(3) The name of an internal array (such as the input buffer)
containing data. This is the manner by which you can re-read
a data record. explanation: on any read, the data is read into
the input buffer as raw data. If a format has been specified,
the record is transformed into the corresponding input fields.
But: even after formatting, the raw data is still in the input
buffer.
FMAT is a parameter that specifies whether explicit or list-directed
formatting is to be applied. It may take either of the following
forms.
(1) A statement label of a format statement. The statement label
must begin with a numeric character 0-9. The rest of the label
can be anything of your own choosing.
(2) '*' that specifies list-directed formatting.
If FMAT is omitted, a 'null' read is performed, effectively passing over
an input record. The unformatted contents of the record are not lost,
however, but are preserved in the input-output control buffer (IOCB).
The string is available by its IOCB name, and may be treated as any
other character array.
LIST names the variables, arrays, array elements and character strings
to which data will be transferred.
If end of file is sensed, the logical variable 'EOF' is set to TRUE.
2-4
FORMATTED READ
Syntax: READ(UNIT,FMAT]) list
This is a two-step operation.
Step 1 reads the record into the IOCB (an unformatted read).
Step 2 applies the formatting and transforms the ascii data into the
various input fields.
LIST-DIRECTED READ
Syntax: READ(UNIT,*) list
Read statements are either unformatted or formatted. The difference in a
list-directed read is that the compiler is going to create a format for
itself, based on what kind of data we have in the 'list'.
This is a two-step operation.
Step 1 reads the record into the IOCB (an unformatted read).
Step two applies the compiler-designed formatting and transforms the
ascii data into the various input fields.
NEXCHAR
Reads a character from the keyboard. Does not echo to the console. If
no character is ready, waits for operator to enter one. The character
is available to the program in register AL. Execution resumes.
See 'testall.for' for a practical example. (NEXCHAR and WAIT are same)
2-6
LIST-DIRECTED WRITE
Syntax: WRITE(UNIT,*) list
In a list-directed write, a format is constructed by the compiler based
upon the data type of the various fields. Other than that, it is exactly
like the formatted write.
While most compilers require that the first character of an output record
be used for carriage control, SBM fortran does not. When output is to be
directed to a printer, feel free to insert ascii control codes, 0Ch for
eject, 0Dh for double space.
SHOW_CHAR
Display the character that is in the AL register. You can use this
statement immediately after NEXCHAR.
SHOW_CHAR 'char'
Display specific character. The character can be a printable
character enclosed in quotes, or a hex constant.
Example: show_char 8 gives us a back-space on the console.
3-2
SUBSCRIPTING
Any variable may be accessed by using the variable name in a fortran
statement. To access variables in positions other than the first, you
must (1) use an integer offset or (2) use a subscript.
An integer offset may be used by simply appending the variable name with
a plus-or-minus constant. Example: 'ARRAY+4' points to the fifth
position of a integer*1 or character array. If the array was integer*2,
it would point to the third position, since each element in an integer*2
array requires two positions. While this is not a standard fortran
method of accessing data, it is by far the most efficient.
Subscripts, on the other hand, indicate the position of an element by
enclosing a subscript expression within a pair of parentheses.
The subscript expression can be an integer constant, and integer
variable, or an integer variable plus-or-minus an integer constant.
Examples: array(k), date(m+2), etc..
Other informative examples can be found in the program 'TESTALL.FOR'.
A word of caution: Do not allow the expression to go negative. You will
access something, but who knows what...
4-2
CONTROL STATEMEMTS
CMP variable, constant
Compare a variable to a known value. This statement is identical to it's
ASM equivalent. Subscripts are not permitted, but offsets can be used.
Usage: CMP Name, 'A'
CMP Name+2,'B'
CMP Year, 99
This statement essentially subtracts the constant from the variable, does
not change any values in memory but, sets the control flags. You must
then use a conditional jump for program control.
COMPARE
Compare a string of characters against a model. Not case sensitive,
'TOKEN' should be upper case.
Usage: COMPARE KEWORD, 'TOKEN'
Example, from the compiler.
- see if prefix 'byte' or 'word'
compare keword,'BYTE' ;
if(eq) goto destin_ok ; if 'byte' or 'word',
compare keword,'WORD' ; accept it as-is.
if(eq) goto destin_ok ;
GOTO Unconditional transfer of control.
JMP Same as GOTO
WAIT
Wait for operator. Program execution stops. When operator has pressed
any key, execution resumes.
PAUSE ['message']
Stops, waits for operator. If message included, displays the message.
Otherwise, displays the phrase 'FORTRAN PAUSE'. Execution of the program
will continue with the press of any key.
STOP, CALL EXIT
Use either to close all files, update directory and return control
to the operating system.
4-4
IF statements
An IF statement conditionally executes one statement or a block of
statements.
The IF statement has the form:
IF (exp) stmt
Where exp is a logical or relational expression.
In a LOGICAL IF statement, we have, as the result of a TEST or
input/output operation, a condition of true(non-zero) or false(zero). The
statement, or block of statements, will be executed only if the condition
is true. In a logical IF, exp simply names the logical variable. In
addition to the normal variable names, SBM fortran also allows the
following:
(EQ), (NE), (ZR), (NZ), (CY), (NC)
or (EOF), (NOT.EOF), (NUMERIC), (NOT.NUMERIC)
stmt can be any non-labled executable statement, but not another IF.
The RELATIONAL IF statement performs an on-the-fly comparison of a
variable to a known value.
Character-strings can be compared, no matter what their length, but only
for EQ or NE. Other operators may be used, but use with caution. The
comparison is NOT case sensitive.
The relational IF has the following syntax:
IF (VARIABLE.OP.Constant) stmt
where OP will be EQ, NE, LT, GT, LE, GE
Constant may be (1) numeric,
(2) Ascii character (excluding ';' and '|') , or
(3) AsciiZ string.
4-6
The block IF conditionally executes blocks of statements. It has the
following form:
IF (exp) THEN
block
ELSE
block
ENDIF
where:
exp is a logical expression.
THEN must appear on the same line.
block is a series of statements, none of which can be another block-IF.
The ENDIF terminates the block-IF construct.
4-8
DO Statement
Here you can specify that a block of statements be executed for a
specific number of times.
Syntax: DO label index=first,last
where: label is a numeric statement label of a CONTINUE statement which
is forward from this statement.
index is an integer*2 variable that will be set, and then
incremented.
first is an integer constant.
last is an integer constant.
CONTINUE statement
Used only in conjunction with the DO statement, this statement is labled
and is used as the terminator of the block of statements to be executed.
Example: from "testall.for"
do 809 counter=1,10
write(16,309) counter
309 format('test output record',i3)
809 continue
6-2
MISCELLANEOUS INTRINSIC FUNCTIONS
PARSE STRING, KEY [, 'delims']
Given the ascii STRING, isolate the first token. Copy the isolated token
to KEY and shift STRING left to remove the token KEY. Delimiters are
blank, comma or equals. Carry is set if no data available to parse (EOR).
You can specify an additional list of delimiters to be used.
Example: Consider the string 'now is the-time'
parse string,keword,'(/-+'
After the parse, keword will be 'now'
string will be 'is the-time'
carry is not set.
PARSE_ONLY String, Keword, 'char'
Parse until a specific character is found. We ignore the standard
delimiters. In fact, the standard delimiters (including blanks) are
passed to the 'keword' array.
Example: As above, the string 'now is the-time'
parse_only string, keword,'-'
After the parse, keword will be 'now is the'
string will be 'time'
LDA Load address to a register: LDA VARIABLE, REG
UPCASE Convert a character string to upper case.
Usage: UPCASE String