• Aucun résultat trouvé

i Assembler Program Conventions

Dans le document Information When (Page 45-53)

Terms

You must follow certain conventions and rules for using terms and expressions, for addressing, and for linking references.

Programs are assembled to begin at address 0000, unless you use the START statement to specify a different address. If you do not specify a 2K boundary when you specify the beginning address, the program will begin at the next higher 2K boundary.

When a data constant is used in the operand of an instruction, the constant's address is assembled into the instruction.

You should understand the meanings of expression and term to follow the rest of this chapter. A term is a single symbol, a self-defining value, or a location counter reference in the operand of an assembler language statement. The three types of terms are described under Terms in this section. An expression consists of one or more terms and makes up the operand field of an assembler language instruction.

Terms and expressions are classed as either absolute or relocatable. (see table on page 1-14)A term or expression is absolute if its value is not changed when the assembled program in which it is used is loaded into main storage and is relocatable if its value depends on addresses within the program.

Every term represents a value, a constant. This value can be assigned by the assembler program (for symbols and for location counter references) or can be part of the term itself (self-defining).

An absolute term is a nonrelocatable symbol, or any of the self-defining terms.

Arithmetic operations are permitted between absolute terms.

Chapter 2.Using IBM System/36 Assembler Programming Language

2-5

Symbols (Symbolic Terms)

A symbol is a character or combination of characters used to represent a storage location, a register, or a value.

Symbols can be used as label entries and operand entries. This is an easy way to name and refer tq a field or an instruction. Symbols used as label entries·in a source statement are assigned values and a length attribute by the assembler.

The value assigned to a symbol in the label entry of a machine-instruction statement is the address of the leftmost byte of the storage location containing the statement. The values assigned to symbols naming storage areas and constants are the addresses of the rightmost bytes of the storage fields containing these items. The symbols naming storage areas and constants are considered relocatable terms because the address of an area or constant might change.

A symbol that is a label entry in an equate symbol assembler instruction

statement (EQU) is assigned the length and the value designated in the operand of the statement. You can have the operand represent a relocatable value or an absolute value. The length attribute of the symbol on an EQU instruction is the length of the operand entry (or operand 2, if specified).

The value of a symbol cannot be a negative number and cannot exceed 65535.

The length attribute, if specified, must be from I to 256.

EQU statements require that a symbol in the operand be previously defined. A symbol is defined when it appears as the label of a source statement or the operand of an EXTRN instruction.

A symbol used as a label in a statement or operand of an EXTRN instruction can be defined only once in an assembly.

PROGRAM PROGRAMMER

Constants (Self-Defining Terms)

A constant is a term whose value is shown by the term. When a self-defining term is used in a machine-instruction statement, its value is assembled into the instruction. It is not assigned a value by the assembler. For example, the decimal term 15 represents a value of 15.

Constants have the following characteristics:

• The length attribute of a constant term is always 1.

• Constants specify machine values or bit configurations without equating the values to symbols and then using the symbols.

• Constants are always right-justified. Truncation and padding with O's occurs from the left.

The four types of constants are: decimal, hexadecimal, binary, and character.

Each term is a representation of a corresponding machine-language bit configuration. Constant terms are used to specify program elements such as immediate data, masks, registers, displacements, lengths, addresses, and address increments. The use of decimal, hexadecimal, binary, or character constants depends on what you are specifying.

Decimal Constants: Consist of decimal numbers written as a set of decimal digits.

High-order O's can be used (for example, 007). A decimal constant is assembled as its binary equivalent. A decimal constant cannot consist of more than 5 digits or exceed 65535. A decimal constant that represents an address should not exceed the size of storage. Some examples of decimal constants are: 8, 147, 4092, and 00,021.

In the following example, a decimal constant is used in a move immediate (MVI) machine instruction. The I-byte area referred to by the symbol, COST, will contain the decimal value 25 (binary 0001 1001) after the instruction in an assembled program is performed.

STATEMENT

... Openolion Operand R ... rks *

011 121314151817 181920 2122232425 26 27 282930 3132333435 36 37 38 39 40 4142434445 4647484950 51525354 56 56 57585980 6162636466 6667686970717273 ;

Chapter 2.Using IBM System/36 Assembler Programming Language 2-7

PROGRAM PROGRAMMER

Hexadecimal Constants: Consist of the letter X (coding character for hexadecimal), followed by one to four hexadecimal digits (0 through 9, A through F) enclosed in apostrophes. An example is X' 4A9'. Each hexadecimal digit is assembled as its 4-bit binary equivalent, in this case, as 0100 1010 1001. The largest hexadecimal constant is hex FFFF.

The hexadecimal digits and their bit patterns are as follows:

Digit Bit Pattern Digit Bit Pattern

0 0000 8 1000

1 0001 9 1001

2 0010 A 1010

3 0011 B 1011

4 0100 C 1100

5 0101 D 1101

6 0110 E 1110

7 0111 F 1111

The following is an example of a hexadecimal constant term. The I-byte area referred to by the symbol SWITCH would contain the hexadecimal value FO (binary 1111 0000) after the instruction is performed.

STATEMENT

&..bel Operation a-and R_rIII

011 121314151617 181920 2122232425 26 27282930 31 323334 35 36 37383940 41424344 46 46 47 4B 49 50 51525354 &Ii 56 57 58 5950 61626364 &Ii 66 67 68 69707172 ;

Binary Constants: Consist of the letter B(coding character for binary), followed by an unsigned sequence of l's and O's enclosed in apostrophes, as follows:

B'lOI01101'. This term would occupy 1 byte of storage. A binary constant can have up to 16 bits. Binary terms are used in logical operations or to designate bit patterns of masks.

The following example illustrates a binary term used as immediate information in a move immediate (MVI) machine instruction. The byte of information replaces the byte of information referred to by the symbol BETA.

Character Constants: Consist of the letter C, followed by characters enclosed in apostrophes. Letters, decimal digits, and special characters can be used in a character constant. In addition, any character available on an input device can be entered. The following are examples of character constants:

e'I' e'AB' e'13'

Each character in a sequence is assembled as its EBCDIC equivalent. Because apostrophes are used as characters in the syntax of the assembler language, two apostrophes must be written as input for each apostrophe desired in a character constant as output. For example, you would write the character value A' as C' A". In the following example, a dollar sign ($) would be moved into the I-byte field at REPORT.

Chapter 2.Using IBM System/36 Assembler Programming Language

2-9

Expressions

An expression is an arithmetic combination of terms. The arithmetic operators used to combine terms into expressions are:

+ Addition Subtraction

*

Multiplication

The following are examples of valid expressions:

AREA+X'2D' N-25 5*X'Cl' *+15

AREA value plus a N value Decimal 5 times Current value of hexadecimal 2D minus a the hexadecimal the location

decimal 25 CI (result is counter plus decimal 965) decimal 15 The rules for coding an expression are:

• Blanks are not allowed in an expression.

• Parentheses cannot be used in an expression.

• In a multiplication operation, only absolute terms can be used.

• Two terms or two operators must not be used consecutively in an expression.

• When an expression contains an external symbol, the symbol must have the form A or A

±

e~ where A is the symbol used as the operand of an EXTRN statement and e is an absolute expression. Any symbol equated to an expression like this cannot be used in an expression that has more than one term.

If the expression has more than one term, the terms are reduced to a single value as follows:

• Each term is evaluated separately.

• Arithmetic operations are performed in a left-to-right sequence, with multiplication operations performed before addition or subtraction

operations. For example: A + B*C would be evaluated as A + (B*C), not (A+B)*C.

The intermediate result of an expression evaluation is a 3-byte or 24-bit value.

Intermediate results must be in the range of _224 through 224-1. Negative values are carried in the twos complement form.

The final result of an expression is a 2-byte value, the tru~cated, rightmost 16 bits of the result. In an address constant, the amount of truncation and the length of the result depend on the length of the constant. The value of the expression before truncation must be in the range of -65536 through + 65535 (_216 through

216_1). The result will not be a negative number. A negative result is considered to be a 2-byte positive value.

Absolute Expressions: Contain relocatable terms or a combination of relocatable and absolute terms under the following conditions:

• The expression must contain an even number of relocatable terms.

• The relocatable terms must be paired, and each pair must consist of terms with opposite signs. Paired terms need not be next to each other.

• Relocatable terms cannot be used in a multiplication operation.

Because both terms would be relocated by the same value, pairing relocatable terms with opposite signs cancels the effect of the relocation. The value represented by the paired terms remains constant regardless of the program relocation. For example, in the absolute expression A - Y + X, A is an absolute term and X and Yare relocatable terms. If A equals 50, Y equals 25, and X equals 10, the value of the expression would be 35. If X and Yare relocated by a factor of 100, their values would become 110 and 125, respyctive1y. However, the expression would still evaluate as 35 (50-125+ 110=35).

Relocatable Expressions: Contain a combination of relocatable and absolute terms under the following conditions:

• There must be an odd number of relocatable terms.

• All re10catable terms, except one, must be paired, and each pair must consist of terms with opposite signs. The paired terms need not be next to each other.

• The unpaired term must not immediately follow a minus sign.

• Relocatable terms cannot be used in a multiplication operation.

• Every relocatable expression must reduce to a positive value.

All of the terms in a relocatable expression are combined and reduced to a single value. This is the adjusted value of the unpaired relocatable term after it is displaced by the values of the other terms in that expression. For example, in the expression W - X + Y where W, X, and Yare relocatable terms, and W = 10, X

= 3, Y = 1 before relocation, the result is the relocatable value of 8.

If this program is relocated by 100 bytes, the resulting value of the expression would be increased by the amount of relocation (l00), giving the expression a value of 108.

In the following expression, a combination of absolute and relocatable terms are used: A + F*G - D + B. A, D, and Bare relocatable terms; F and G are absolute terms. Given the values A = 3, B = 2, D = 5, F = 1, and G = 4.

The multiplication occurs first, resulting in 4; then the addition and subtraction of the other terms, including the result of the multiplication, is performed in a left-to-right direction. The result of the arithmetic operations is a relocatable value of 4.

Chapter 2.Using IBM Systemj36 Assembler Programming Language 2-11

The value of this expression after relocation can be: d~tenpinpd }~~:~9P'ing

...

~p.~.

amount of relocation to the relocatable result. .

Dans le document Information When (Page 45-53)

Documents relatifs