Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Wa0000.

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

Assembler

• Assembler is a language processor that converts assembly


language program to machine language program.

MOV id3, R1
0000 1100 0010
MUL #2.0, R1
0111 1000 0001
MOV id2, R2
Assembler 1111 0101 1110
MUL R2, R1
1100 0000 1000
MOV id1, R2
1011 0010 1010
ADD R2, R1
1001 1000 1001
MOV R1, id1
1100 0000 1000
Assembly Error Machine
language Messages (If any) language
program program
Computer Science & Engineering – 18CS61
Role of Assembler

Source Object
Assembler Code Linker
Program

Executable
Code

Loader

Computer Science & Engineering – 18CS61


Assembler Directives
▪ Pseudo-Instructions
• Not translated into machine instructions
• Providing information to the assembler
▪ Basic assembler directives
• START
• END
• BYTE
• WORD
• RESB
• RESW

Computer Science & Engineering – 18CS61


Functions of a Basic Assembler
■ Convert mnemonic operation codes to their machine
language equivalent
■ Convert symbolic operands to their equivalent machine
addresses
■ Decide the proper instruction format
■ Convert the data constants to internal machine
representations
■ Write the object program and the assembly listing

Computer Science & Engineering – 18CS61


Two-Pass Assembler
▪ Pass 1
• Assign addresses to all statements in the program
• Save the values(addresses) assigned to all labels for use in Pass 2
• Perform some processing of assembler directives
▪ Pass 2
• Assemble instructions by translating operation codes and looking up
addresses
• Generate data values defined by BYTE, WORD
• Perform processing of assembler directives not done in Pass 1
• Write the object program and the assembly listing

Computer Science & Engineering – 18CS61


Assembler Algorithm and Data Structures
Our simple assembler uses 2 internal data structures
 Operation code Table (OPTAB)
 Symbol Table(SYMTAB)
 Location counter(LOCCTR)

▪ Location counter(LOCCTR) is a variable that is used to help in the assignment


of addresses
▪ LOCCTR initialized to be beginning address specified in the START statement.
▪ After each source statement is processed the length of the assembled instruction
or data area to be generated is added to LOCCTR
Data structures- OPTAB(operation table)
▪ OPTAB contains the mnemonic operation code and its machine language
equivalent.
▪ In more complex assemblers, this table also contains information about
instruction format and length.
▪ During pass1,OPTAB is used to look up and validate operation codes in the
source program.
▪ In pass2 , it is used to translate the operation codes to machine
equivalents
▪ OPTAB is usually organized as hash table, with mnemonic operation code as the
key.
▪ OPTAB is a static table- that is entries are not normally added or deleted from it.
Data structures- SYMTAB(Symbol Table)
▪ Symbol table(SYMTAB) includes the name and value(address) for each label in
the source program, together with flags to indicate error conditions.
▪ During Pass 1 of the assembler, labels are entered into SYMTAB as they are
encountered in the source program, along with their assigned addresses(from
LOCCTR).
▪ During Pass 2,symbols used as operands are looked up in SYMTAB to obtain
addresses to be inserted in the assembled instructions.
▪ SYMTAB is usually organized as hash table for efficiency of insertion and
retrieval.
Example program with object
code (Figure 2.2 pp. 47)
Example program with object
code (Figure 2.2 pp. 47)
Example program with object
code (Figure 2.2 pp. 47)
Format of object
program (Figure 2.3
■ pp.49)
Header record
Col. 1 H
Col. 2~7 Program name
Col.8~13 Starting address of object program (hex)
Col. 14- Length of object program in bytes (hex)
19
■ Text record
Col. 1 T
Col. 2~7 Starting address for object code in this record (hex)
Col. 8~9 Length of object code in this record in bytes (hex)
Col. 10~69 Object code, represented in hex (2 col. per byte)
■ End record
Col.1 E
Col.2~7 Address of first executable instruction in object program (hex)

■ “^” is only for separation


Format of object
program (Figure 2.3
pp.49)
References

1. System Software by Leland. L. Beck, D Manjula, 3rd edition, 2012


Alfred V Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman ,
2. Compilers-Principles, Techniques and Tools, Pearson, 2nd edition,
2007
3. Doug Brown, John Levine, Tony Mason, lex & yacc, O'Reilly
Media, October 2012.
4. Systems programming – Srimanta Pal , Oxford university
press,2016
5. System programming and Compiler Design, K C Louden, Cengage
Learning
6. System software and operating system by D. M. Dhamdhere TMG

Computer Science & Engineering – 18CS61

You might also like