Instructions The instruction is the fundamental element in - TopicsExpress



          

Instructions The instruction is the fundamental element in program preparation. Debugging Errors caused by faulty logic and coding mistakes are referred to as bugs. Finding and correcting these mistakes and errors that prevent the program from running and producing correct output is called debugging Assembly and compiler programs prepare your program (source program) to be executed by the computer and they have error diagnostic features which detect certain types of mistakes in your program. Documentation Documentation is a continuous process, beginning with the problem definition. Documentation involves collecting, organizing, storing, and other-wise maintaining a complete record of the programs and other documents associated with the data processing system. Flowcharting is a pictorial means of representing a procedural solution to a problem in which different shaped symbols are used to represent operations, data, flow, equipment and so forth. There are two types of flowcharts— system (data) and programming. The tools of flowcharting are: (1) fundamental symbols; (2) graphic symbols; (3) flowcharting template; and (4) flowcharting worksheet. Instruction Set The number of instructions in a computer’s instruction set may range from less than 30 to more than 100. These instructions may be classified into categories such as input/output (I/O), data movement, arithmetic, logic, and transfer of control. Input/output instructions are used to communicate between I/O devices and the central processor. Data movement instructions are used for copying data from one storage location to another and for rearranging and changing of data elements in some prescribed manner. Arithmetic instructions permit addition, subtraction, multiplication, and division. They are common in all digital computers. Logic instructions allow comparison between variables, or between variables and constants. Transfer of control instructions are of two types, conditional or unconditional. I. Conditional transfer instructions are used to branch or change the sequence of program control, depending on the outcome of the comparison. If the out-come of a comparison is true, control is transferred to a specific statement number; if it proves false, processing continues sequentially through the program. II. Unconditional transfer instructions are used to change the sequence of program control to a specified program statement regardless of any condition. The instructions which are preceded by line numbers are called statements. A complete set of statements to solve a problem is called a program. The very last statement in each program must be the END statement STATEMENT NUMBER.—(Frequently referred to as line number). This number has two vital functions: (1) To identify the statement itself (statement label); and (2) To indicate to the BASIC compiler (interpreter) where you want this statement placed in the program sequence. The statement number must be an integer (a whole number—no decimal parts or fractions). For the purpose of this text, the range for statement numbers is from 1 to 99999. BASIC LANGUAGE KEYWORD.—Keywords are used to tell the computer what function is to be performed by this statement. DESCRIPTIVE INFORMATION.—This information completes the description of the function to be performed and varies with the keyword used. Duplicate statement numbers are not allowed. If two statements are entered with the same statement number, the computer will accept the second statement with the duplicate statement number and replace the first. You may also delete a line by typing the command DELETE and the line number, Another way to delete a line is to type in only the line number and depress the RETURN key, To help find logic errors, you may find it useful to include some documentation about the program within it. To do this, you use the REMARK statement. Predefined Functions FUNCTION ABS (X) ATN (X) COS (X) EXP (X) INT (X) LOG (X) RND (X) SGN (X) SIN (X) SQR (X) TAN (X) DESCRIPTION Absolute value of X Arc tangent of X in radian measure Cosine of X in radian measure Natural exponential of X The largest integer not greater than X Natural logarithm of X (base e) Generates random numbers between 0 and 1 Algebraic sign of X: -1 if X0 Sine of X in radian measure Square root of X Tangent of X in radian measure The REMARK statement is a non-executable statement When a statement with the keyword REMARK is used, the entire line on which the statement appears is considered a comment. REMARK statements be used at the beginning of a program, they can be used throughout the program to separate different segments of a program and to introduce subroutines or loops. Instructions which are preceded by line numbers are called program statements. The parts of a statement are: and descriptive information. The BASIC character set is divided into three categories: alphabetic, numeric, and special characters. E notation (scientific notation) is used for representing very large and very small numbers. Line numbers tell the computer the sequence of the instructions in your program. The first step in entering in a statement is keying in the line number. The system command LIST causes your program to be listed with the statements in ascending sequence by line number System command RUN is used to tell the computer to execute the program. The REMARK statement is used to aid in documenting your program. There are three types of characters used in BASIC. These are: (1) Alphabetic (2)Numeric (3) Special characters. ALPHABETIC CHARACTERS.— The alphabetic characters used in BASIC are the standard English alphabet, A through Z. NUMERIC CHARACTERS .—The numeric characters used in BASIC are the digits 0 through 9. SPECIAL CHARACTERS.—The following are special characters used in BASIC: OTHER SPECIAL CHARACTERS.—Some special characters are com-bined to form other elements in BASIC. The following list shows these com-binations: > = greater than or equal < = less than or equal not equal ** exponentiation You cannot use $ (dollar sign), ‘‘, (comma), or the / (slash) in a BASIC number Valid BASIC Numbers 99.95 100000.00 +5678901.2 Invalid BASIC Numbers $99.95 100,000.00 +567890100 1/4 Explanation Dollar sign cannot be used Comma cannot be used Too many digits, only eight are allowed (decimal points, positive and negative signs do not count). Slash cannot be used; however, this is a valid expression as an arithmetic operation CHPT3 ARITHMETIC EXPRESSIONS Arithmetic expressions are composed of a combination of constants, variables, operation symbols, and functions. An expression may be very simple or quite complex, but it will result in a single value. The END statement has two functions---- 1. To indicate to the compiler (interpreter) that there are no more BASIC statements for it to translate 2. To terminate execution of the program Execution of an END statement causes the computer to print a message which indicates program execution is terminated and that the computer is ready for further processing. Standard spacing, divides the print line into a specified number of print zones or fields of a predefine length packed spacing maybe achieved through the use of punctuation in the PRINT statement. LET Statement It is an instruction to the computer to either assign a specified value to a variable name, or to do certain computations and then assign the result to a variable name The LET statement is not a statement of algebraic equality; rather, it is a definition that assigns a value or a number to a variable. The LET statement can be used to assign a constant value to a variable name, a variable to a variable name, or the result of an expression to a variable name. The LET statement is often referred to a statement. Three important points to remember about the LET statement are: I. It assigns a value to a variable name. II. The value may be expressed as a constant, another variable or an expression. III. The value is stored in memory and may be referenced by its variable name. Numeric-variable Name A numeric-variable name is an arbitrary name that you select, and you and the computer system use to refer to some location in memory. String-constants and String-variables They may be a series or string of characters such as name OR ADDRESSES The important things to remember about constants and variables are: 1. Numeric-constants are whole or decimal numbers that do not change throughout a program. 2. Variables, referenced by variable names, may represent numeric values or character strings. 3. Variables are used when values may change during execution of a program. 4. Variable names for numeric values may be a single alphabetic character (A-Z), or one alphabetic character followed by a single numeric digit (0-9). 5. Variable names for character strings are a single alphabetic character (A-Z) followed by a dollar sign ($). 6. String constants are character strings that do not change The parentheses rule says: . Computations inside parentheses are performed first. . If there are parentheses inside parentheses, the operations inside the inner pair are performed first. In the BASIC language, we have two ways to refer to a numeric value: 1. By a numeric-constant representing the value, 2. By an arbitrary name, a numeric-variable name, representing the value. Numeric-constants A numeric-constant is a decimal number, whose value does not change. ****The function of the PRINT statement is to instruct the computer to output something, either on the terminal or the printer. The print statement prints the value of a single variable. The commas will give you standard spacing while semicolons give packed spacing. The print statement is also Printing the results of a computation. The two primary punctuation marks used in a PRINT statement are the comma and semicolon. COMMA.—When a comma is used as a separator in a PRINT statement, standard spacing (16 spaces per field) is achieved. A comma maybe used at the end of a PRINT statement to allow the information in the following PRINT statement to be printed on the same line. SEMICOLON: When a semicolon is used in a PRINT statement, messages are printed together without any spaces (packed spacing). Important keys to note about the Print Statement include: 1. It will print any message enclosed in quotation marks. 2. It will print any number or variable. 3. It will calculate and print the result of an expression. 4. A blank PRINT statement will cause a blank line in your output. 5. When a comma is used as a separator, normal spacing (16 spaces per field) is achieved. 6. When a comma is used at the end of a PRINT statement, the data in the next PRINT statement is continued on the same line beginning in the next print zone. 7. When (quote, blank, quote) is used as a print field the computer will skip to the next print field. You are actually telling the computer to print a blank field. On some computers, two commas (,,) together will produce the same results. 8. When a semicolon is used as a separator, packed spacing is achieved. 9. When a semicolon is used at the end of a PRINT statement. the information contained in the next PRINT statement is continued on the same line. 10. PRINT statements can become awkward when many computations are to be done or the results of computations are to be used in other calculations. CHPT 4 The change in the normal sequence of execution is called transfer of control branching/statement It is of two categories: They are conditional and control The control statement, GOTO, which specifies the line number to which control is to be transferred. The GOTO creates a loop..... A loop is any sequence of statements that is to be repeated some specified number of times, or until a particular condition is met The GOTO allows many branches or alternative paths. With the READ and DATA statements, the data is stored in the program. With the INPUT statement, the data is entered during program execution. statement controls the loop and transfers control..... The IF-THEN statement causes a change in execution sequence only on meeting a particular condition of data. The IF-THEN statement allows the computer to follow one of two possible paths. The IF-THEN statement used as a tool for branching to a different area of a program. The RESTORE statement is used to reset the pointer to the top of the data list. READ statement executed starts reading data from the top of the data list. Input statements are used if data is to be supplied during program execution. They can be placed anywhere in a program prior to the statements that need the data. Only variable names are used in the INPUT statement, no values may be placed in the INPUT statement. Data provided using the INPUT statement is entered during program execution but is not saved as part of the program once the program has been run SUMMARY OF CHPT 4 Transfer of control statements may be used in a program when you do not want to execute statements in sequence, or when you want to execute a group of statements repeatedly, forming a loop. The unconditional transfer of control statement, GOTO, is used when you always want to alter the normal sequence, either to bypass some statements or to branch back to the beginning of a loop. The conditional transfer of control statements, IF-THEN and ON-GOTO are used when you only want to change the normal sequence of execution if given conditions exist. These can be used to control a loop or to branch to selected statements. CHPT 5 A subroutine is defined as a small program within another program. Subroutines can be used when sets of instructions are to be performed several times in one or more programs. They can also be useful when more than one programmer is working on a program To execute a subroutine, you must transfer control to the subroutine by using the keyword, GOSUB. The GOSUB statement is used to transfer control to a subroutine. It is made up of a statement number followed by the keyword GOSUB and the number of the first statement in the subroutine. The RETURN statement is used to transfer control back to the main program. It must be the last statement in the subroutine. Therefore, the GOSUB and RETURN statements in transferring control to a subroutine and returning control back to the main program. The STOP statement, terminates execution of the program. A numeric variable, called a running variable is used to control the number of times a loop is executed. A loop may have another loop inside it. This is called a nested loop. The DIM (DIMENSION) statement is used to define the size of an array. It reserves space in the computer’s memory for the specified number of elements. An array may contain either numeric or string data; Control can be transferred out of a loop but not in. (The transfer out can be done by using a GOTO, an ON-GOTO, or an IF-THEN statement.) The DEF statement consists of a statement number, the keyword DEF and the function definition for defining functions. The function definition consists of the function name, followed by an equal sign, followed by a constant, variable, or expression. Both numeric and string functions may be defined with the DEF statement. Numeric functions return numeric values and string functions return string values. Numeric function names must consist of three letters, the first two must be FN, followed by any single letter of the alphabet (A-Z). String functions must consist of three letters followed by a dollar sign. FOR-NEXT—for simplifying loops DIMENSION and subscripted variables—for processing data in tables (arrays of one or more dimensions) Predefine functions—for computing commonly used mathematical functions DEF—for defining your own functions GOSUB and RETURN—to allow the use of subroutines STOP—to terminate program execution anywhere in a program The variable used to control the loop is also used as the subscript for S in the READ statement. The BASIC programming language automatically assigns 11 elements to every one-dimensional array Summary--- DIMENSION statements are used to define arrays. The elements in an array can be either numeric quantities or strings. However, all of the elements in a given array must be the same type (all numeric or all string). An array that contains numeric elements must be named with a single letter. A string array is referred to with a letter followed by a dollar sign. Elements in a one-dimensional array are referenced by the array name followed by a subscript in parentheses, A (l). Elements in a two-dimensional array, matrix, are referenced by the name followed by two subscripts in parentheses; the first References the row, the second the column, A(2,3). Subscripts may be a numeric-constant or a numeric-variable. Each array name in a program must be unique. However, an array and an ordinary variable can have the same name. Duplicating array names and variable names could be logically confusing; therefore, it is not a recommended practice. CHAPT 6 PRINT USING STATEMENT The PRINT USING statement allows greater flexibility in formatting printed output. Format control characters are used to describe output images and to position data in the output line TAB FUNCTION The TAB function allows output to be printed in any location of an output line. When a TAB function is used in a PRINT statement it must immediately precede the constant or variable to which it applies. The TAB function is useful in formatting various types of printed output. One use is in formatting headings for reports. CHPT 7 A data file is any group of related records, such as inventory, personnel, payroll, manhour accounting,
Posted on: Thu, 07 Nov 2013 17:52:58 +0000

Trending Topics



Recently Viewed Topics




© 2015