Machine Independent

Published on February 2018 | Categories: Documents | Downloads: 33 | Comments: 0 | Views: 422
of 10
Download PDF   Embed   Report

Comments

Content

MACHINE INDEPENDENT FEATURES OF ASSEMBLER The assembler features that are not closely related to machine architecture are , 1. Literals 2. Symbol defining statement 3. Expressions 4. Program blocks 5. Control section

1. LITERALS Literal is a constant operand which is used to write the value of it as a part of the instruction. This avoids having to define the constant elsewhere in the program and make up a label for it. Literal is defined using the notation *= constant value. Definition of literals: *=C’EOF’ *=X’05’ *=X’F1’ *  Indicate the current value of the location counter. For example, in *= C’EOF’ , the string constant EOF (internal machine representation in binary) is generated and stored in the current memory location address. The notation, = constant value used for literals varies from one assembler to another but most assembler use symbol = to make literal identification easier *= constant value  object code internal representation of constant value *=C’EOF’  454F46 in hexadecimal ASCII

Usage of literals Opcode = constant value Examples are: LDA = C’EOF’ TD = X’05’ TD=X’F1’ DIFFERENCE BETWEEN LITERAL &IMMEDIATE ADDRESSING With immediate addressing, the operand value is assembled as part of the machine instruction Eg: LDA

#3

011003

With literal, the assembler generates specified value as a constant at some other memory location .the address of this generated constant is used as target address for the machine instruction Eg : 0030

LDA = X’3’

0033 : 0059

*=X’3’

LITERAL POOL: All the operands used in the program are gathered together into one or more literal pools. Normally literals are placed into a pool at the end of the program In some cases it is desirable to place literals into a pool at some other location in the object program using the directive LTORG (LITERAL ORIGIN).

When the assembler encounters the LTORG statement, it creates a literal pool that contains all of the literals operands used since the previous LTORG or the beginning of the program Literals placed by LTORG will not be repeated at the pool at the end of the program .The duplicated literals are recognized by comparing the generated value of the constant operands Eg: usage of literals

LDA = C’EOF’ LDA = X’454F46’ :

Definition of literals



*= C’EOF’

454F46

*=C’454F46’

454F46

Literals can be used to refer to the current value of the location counter (address of the memory location)

Eg : base LDB •

object code

* =*

The above instructions are used to specify the operand with value as current value of location counter.

2. SYMBOL DEFINING STATEMENT: Symbol can be defined in two ways • using RESW and RESB directives • using EQU directives SYMBOL DEFINED USING RESW OR RESB DIRECTIVES: Memory location is allocated for the symbols which are defined using RESW or RESB directives. During pass1, the address of the memory location is stored as value in the symbol table. LOC

opcode

operand

0030

RETADR

RESW

SYMTAB SYMBOL NAME

VALUE

RETADR 0030 MAXLEN

1000

SYMBOL DEFINED USING EQU DIRECTIVE: LOC

SYMBOL

EQU

VALUE

1000

MAXLEN

EQU

BUFFER-BUFEND

• Memory location is not allocated for the symbol defined using EQU

The value of the symbol can be any one of the following:

constant

any expression involving constant

address of previously defined symbol

• During pass1, the name of the symbol and the value assigned to the symbol are stored in the symbol table.

Eg : LOC

symbol

opcode

operand

0

A

EQU

0

1

X

EQU

1

2

L

EQU

2

ORG: ORG is an assembler directive that can be used to indirectly assign to symbols. Format:

ORG

value

Where value is a constant or an expression involving constants and previously defined symbols.

When this statement is encountered during assembly of a program, the assembler resets its location counter (LOCCTR) to the specified value. Since the values of symbols used as labels from LOCCTR, the ORG statement will affect the values of all labels defined until the next ORG.

For example, if the symbol table is defined in the following structure: STAB

100 entries

SYMBOL

VALUE

FLAGS

In this table, the SYMBOL field contains a 6 byte user defined symbol. VALUE is a one word representation of the value assigned to the symbol. FLAGS is a 2 byte field that specifies symbol type and other information. We could reserve space for this table with the statement STAB

RESB

1100

The fields SYMBOL, VALUE, FLAGS are defined individually with the help of EQU statement.

SYMBOL

EQU

STAB

VALUE

EQU

STAB+6

FLAGS

EQU

STAB+9

without using ORG

The same symbol definition can be accomplished using ORG. STAB

RESB

1100

ORG

STAB

SYMBOL

RESB

6

VALUE

RESB

1

FLAGS

RESB

2

ORG

STAB+1100

using ORG

The descriptions of the EQU and ORG statements contain restrictions that are common to all symbol defining assembler directives. In the case of EQU, all symbols used on the right hand side of the statement must have been defined previously in the program. Thus the sequence,

ALPHA

RESW

1

BETA

EQU

ALPHA

would be allowed.

Whereas, the sequence

BETA

EQU

ALPHA

ALPHA

RESW

1

would not.

The reason for this is the symbol definition process. In the second example above, BETA cannot be assigned a value when it is encountered during PASS1 of the assembly because ALPHA does not yet have a value. However, our TWO PASS assembler design requires that all symbols be defined during PASS1.

3. EXPRESSIONS: Assembler allow arithmetic expression format according to the normal rules using the operator +,-,*,&,/ Individual terms in the expression may be  Constant  User defined symbols  Special terms Special term is the current value of the location counter (designated by *) . This term represents the value of the next unsigned memory location. For example , BUFEND

EQU

*

gives BUFEND a value that is the address of the next byte after the buffer area. TYPES OF EXPRESSION • Absolute expression • Relative expression ABSOLUTE EXPRESSION

Value of the expression is independent of the beginning address of the program. Absolute expression may contain only absolute terms or relative terms but it must produce the absolute value Eg: absolute expression that contains the relative terms { relative term represent some location within the program} MAXLEN

EQU

BUFEND-BUFFER Relative format

But produce the absolute value 1000 which is the length of buffer

RELATIVE EXPRESSION: The value of relative expression is dependent of starting address of the program. It may contains relative terms or absolute terms but it must produce the value which is relative to the starting address of the program Eg: SYMBOL

EQU

STAB

VALUE

EQU

STAB+6  1000+6=1006

FLAGS

EQU

STAB+9  1000+9=1009

The values of the expression is 1006 which is some memory location within the program and also relative to the beginning address of the program. To determine the type of an expression we must keep track of the types of all symbols defined in the program. For their purpose we need a flag in the symbol table to indicate type of value (absolute or relative) in addition to the value itself.

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close