0% found this document useful (0 votes)
25 views10 pages

SP Unit-2

The document discusses the assembler, which translates assembly language code into machine-readable object code. It provides details on: 1) The functions of an assembler like translating symbolic instructions and determining instruction formats. 2) The design procedure for an assembler, which involves specifying the problem, data structures, data structure formats, algorithms, and analyzing the design phases. 3) The two pass approach of assemblers, where the first pass defines symbols and the second generates instruction addresses. 4) The databases and data structures used by the assembler like the symbol table, machine opcode table, and pseudo operation table. It also describes the algorithms and flowcharts for the two passes.

Uploaded by

Archana Rajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views10 pages

SP Unit-2

The document discusses the assembler, which translates assembly language code into machine-readable object code. It provides details on: 1) The functions of an assembler like translating symbolic instructions and determining instruction formats. 2) The design procedure for an assembler, which involves specifying the problem, data structures, data structure formats, algorithms, and analyzing the design phases. 3) The two pass approach of assemblers, where the first pass defines symbols and the second generates instruction addresses. 4) The databases and data structures used by the assembler like the symbol table, machine opcode table, and pseudo operation table. It also describes the algorithms and flowcharts for the two passes.

Uploaded by

Archana Rajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Unit-2

Chapter-3
Assembler
Assembler is system software which is used to translate assembly level language into machine
level language program code

Functions of assembler

• Assembler can take an input and produces its machine instructions


• Converts symbolic instructions for each machine instructions
• It decides the proper instruction format
• Converts the data constants to internal machine representations
• Write the object program and the assembly listing

Design procedure for assembler

• Specify the problem statement.


• Specifies data structures (database)
• Define format of data structure
• Specify the algorithm
• Lack for modularity.

Description of above phases:

First we are analyzing the problem statement next we are maintaining the what are the databases
using design proposes next we are getting one format of those database and write algorithm for
the statement and look overview of these steps

Here assembler is designing two pass

• The first pass defines the symbols and literals here we cannot find out the offset value
• The second pass generates the instruction addresses means the offset value.
Step1: statement of a problem

Consider the following source program which has to be converted into machine language(object
program)

JOHN START N0
USING 15
L 1, FIVE
A 1 FOUR
ST 1 TEMP
FOUR DC F‟4‟
FIVE DC F‟5‟
TEMP DS 1F

Intermediate steps in assembling the program

Pass 1 pass2

Relative loc relative address

0 l 1,-(0,15) 0 l 1,16(0,15)
4 A 1,-(0,15) 4 A 1,12(0,15)
8 ST 1,-(0,15) 8 ST 1,20(0,15)
12 4 12 4
16 5 16 5
20 - 20 -
Note: the load instruction add instruction and store instruction are RX instruction format so we
are using relative address 0,4and 8

Step 2: specify data structure (database)

Pass 1: database

1. Input source program

2. Location counter (lc)-it is used to store each instruction location

3. MOT(machine opcode/operation table)-it is used to store mnemonic or symbols for each


instruction and its length.

4. POT(pseudo operation table)-it is used to store the all pseudo opcodes in our source program
and corresponding actions
5. ST(symbol table):it is used to store all the symbol /labels used in our program and its
corresponding value

6. LT(literal table): it is used to store all the literals/constants used in our program and its
assigned location

7. A copy of the input to be used later by pass 2

Pass 2: databases

1. copy of the source program input to pass-1

2. LC:it is used to store each instruction location

3. MOT:it is used to store all directives or mnemonics and its length, binary opcode and
instruction format

4. POT: it is used to store all directives and its action corresponding index

5. ST(symbol table)-it is used to prepare by pass 1 it consists of each label and its value

6. BT(base table)-it is used to store which registers are currently specified as base register by
USING pseudo opcode and it specifies the contents of these registers

7. INST-this is a work space used to store each instruction as its various parts.

Ex: binary opcodes, register fields, length fields etc

8. Print line: it is also work space used to produces a printed listing

9. Punch card: it is also work space used for converting the assembled instructions in the format
needed by the loader.
Format of database

After the second step the third step will be format of those above mentioned databases.

MOT table

• MOT table is used in both pass1 and pass2


• The size of the MOT table will be 6 bytes
• The both passes can take one MOT table.
• In pass-1 the fields mnemonic opcode and instruction length are filled
• In pass 2 the binary opcode and instruction format are filled

Codes

• 01=1 half word=2 bytes


• 10=2 half word=4 bytes
• 11=3 half word=6 bytes

Instruction formats

• 000=RR(2 bytes)
• 001=RX(4 bytes)
• 010=RS(4 bytes)
• 011=SI(4 bytes)
• 100 =SS(6 bytes)

Format of the MOT table

POT table

• This table is a fixed table


• This is similar to the pass 1 and pass2.
• It contains pseudo opcode and corresponding address
• The size of this table is 8 bytes

Format

Symbol table

• It is a variable table
• Same table is used in both pass1 and pass2
• The size of the table is 14 bytes per entry
• The length field indicates the length in bytes of the instruction to which symbol is
attached
• Absolute means the value of the symbol doesn‟t change if the program is moved in core

Format
Literal table

• It is also a variable table


• It contains literal and its values
• It is same as symbol table but instead of storing symbols we were store literals in a table
• The size of the table is 14 bytes per entry

Format

Base table

• It is a variable table
• It is used to specify the base register
• It is used only in pass2
• The size of this table is 4 bytes per entry

Step 4(SPECIFY ALGORITHM):

After the third step next we will go to fourth step of a design that is algorithms and flowcharts of
an assemblers

PASS1 SYMBOLS, FLOWCHART AND ALGORITHM:

The important purpose of a pass1 assembler is to assign location to each instruction and data
defining

Pseudo-ops and define values for symbols appearining in the label field of source program.

ALGORITHM:

1. First we are initialized location counter value is zero because of the relocate location is first
zero value after that based on the instruction formats that will be increased.

2. Next step read the course statement of a source program.

3. In that statement that is pseudo-opcode whether it is which type of pseudo-op.either it is


USING, DROP, END, DS, DC AND EQU. if it is equ pseudo-opcode expression. if it is a dc or
ds

Pseudo-ops it will the attach to the location counter and definition of symbols in pass1.

4. If is LTROG pseudo-opcode the determine the earlier location of the literals.

5. If is END pseudo-opcode pass1 will be terminated.

6. If it is not pseudo-opcode that is machine opcode search for MOT for matching with with the
source

Program and find the length.

7. Repeat these steps upto encounters the END pseudo opcode.


PASS2 SYMBOLS, FLOWCHART AND ALGORITHMS:

The purpose of pass2 is to process each card to find the values and its offset values

ALGORITHM

1. First location counter is initialized as zero

2. Read the statement from source file copied by pass1

3. Process the opcodefield

4. If it is USING pseudo-op or DROP pseudo opcode, then they may require addition processing
in pass2

5. If is a DC pseudo op convert the constant and output it thereby updating LC

6. If it is a DS pseudo opcode then update the LC value

7. If it is END pseudo opcode terminate pass2.before terminating pass2 generating the code for
literals and symbols.

8. If it is a START or LTROG pseudo opcode just print the card in program.

9. If it is a machine opcode then it will store in to the MOT entry and to find length and binary
opcode and format of the instruction format.

10. Again in this pass2 the extra field will be added.

11. It means we will search which type of instruction format it is whether RR, RX, RS, SS etc
STEP 5:Look For Modularity

You might also like