Sei sulla pagina 1di 7

ASSEMBLERS ELEMENTS OF ASSEMBLY LANGUAGE PROGRAMMING An assembly language is A machine dependent Low level programming language Which is specific

fic to a certain computer system or a family of computer systems. 3 basic features are Mnemonic operation codes -: eliminates the need for memorise numeric operation codes and helpful diagnostics
1.

2. Symbolic operands :- The symbolic names can be used as operands in assembly statement. The assembler performs the necessary bindings to these names.
3.

Data declarations : data can be declared in a variety of notations. This avoids manual conversion. Statement format An assembly language statement has the following format. [label] <opcode> <operand spec>[,<operand spec>] [..] means optional. <operand spec> has the following syntax.. <symbolic name> [+<displace ment>] [(<index register>)]

Some possible operands are AREA memoryword AREA+5 : memory word 5 words away from AREA. 5 is the displacement or offset from AREA

AREA (4): operand address is obtained by adding the contents of index register 4 to the address of AREA. Assembly Language Statements An assembly program contains three kinds of statements.. 1. Imperative statements 2. Declaration statements 3. Assembler directives Imperative statements An imperative statement indicates an action to be performed during the execution of the assembled program. Each imperative statement typically translates into one machine instruction. Eg: ADD A,B Declaration statements The syntax of declaration statements is as follows [label] DS <constant> [label] DC <value> DS stands for declare storage and DC stands for declare constant. DS reserves areas of memory and associates names with them.. A G DS DS 1 200

First statement reserves a memory area of 1 word and associates the name A with it. The second statement reserves a block of 200 memory words. The name G is associated with the first word of the block.. Other words in the block can be accessed through offset.. eg : G+5 is the sixth word of the memory block

The DC statement constructs memory words containing constants ..The statement ONE DC 1 Associates the name ONE with a memory word containing the value 1. A literal is an operand with syntax =<value>. It differs from a constant because its location cannot be specified in the assembly program..ie its value is not changed during execution of a program ADD AREG ,=5 (a)

ADD AREG ,FIVE ; ; FIVE DC 5 (b) Assembler directives Assembler directives instruct the assembler to perform certain actions during the assembly of a program.. eg: START <constant> Indicates that the first word of the target program generated by the assembler should be placed in the memory word with address <constant> END [<operand specification>] Indicates the end of the source program . The optional

<operand specification> indicates the address of the instruction where the execution of the program should begin..

DESIGN SPECIFICATION OF ASSEMBLER.. Here we use a 4 step approach to develop a design specification for an assembler.. 1. Identify the information necessary to perform a task.. 2. Design a suitable data structure to record the infn. 3. Determine the processing necessary to maintain the infn in the data structure 4. Determine the processing necessary to perform the task. Analysis phase The key function performed by the analysis phase is the building of the symbol table. For this purpose it must determine the addresses with which the various names used in a program are associated. To determine the address of a name we must fix the address of all other program elements preceeding it. This function is called memory allocation. To implement memory allocation , location counter is used The location counter always contains the address of next memory word in the target program or object program It is initialized to the constant specified in the start statement. Whenever the analysis phase encounter a label in an assembly statement it stores the label and the content of location counter in a new entry of symbol table .It then finds the no. of memory words required by the assembly statement and updates location counter contents. Ie LC always points to the next memory word in the object program even when machine instruction have different lengths. For this purpose it needs to know the no.of memory words required by different instructions This depends on the nature of assembly language and it can be obtained from a table..called mnemonics table.

We refer to the processing involved in maintaining the LC as LC processing Synthesis phase To synthesis the machine instruction corresponding to a statement we must have the following infn
1.

Address of memory word 2.Machine operation code The first item of infn will be available by the analysis phase . And the second infn can be determined by the synthesis phase. The data structures needed during synthesis phase are symbol table and mnemonic table. Each entry in the symbol table has two fields name and address. The table is built by the analysis phase.. Entries in mnemonics table have two primary fields Mnemonic and opcode. The synthesis phase use these tables to obtain the memory address with a name is associated and the machine opcode corresponding to a mnemonic . Hence the tables have to be searched with the symbol name and mnemonic as keys Algorithm for analysis phase

1.

Isolate the label mnemonic opcode and operand fields of a statement

2. If a symbol is found in the label field, enter the pair (symbol, LC contents) in a new entry of symbol table. 3. Check the validity of mnemonic opcode through a look up in mnemonics table. 4. Perform LC processing ie. Update the value of LC by considering the opcode and operands of the statement.. Algorithm for synthesis phase

1.

Obtain the machine opcode corresponding to the mnemonic from the mnemonics table..

2. Obtain address of a memory word from the symbol table.. 3. Synthesis the machine instruction.

Mnemonic ADD SUB

opcode 01 1 02 1 Mnemonics table

length

sSour progr am

A n
Symbol AGAIN N Symbol table. Data access Control transfer Two pass assemblers address 104 113

S y n

STarg etpro gram

The first pass performs analysis of the source program while the second pass performs synthesis of object program. The first pass construct an intermediate program representation.. This representation consists of 2

main components . data structures like symbol table and intermediate code.. Pass 1 Algorithm
1. Seperate 2. 3.

the symbol mnemonic opcode and operand fields

Build the symbol table. Perform LC processing

PassII algorithm Synthesis of the target program.

Potrebbero piacerti anche