Sunteți pe pagina 1din 7

Department of Computer Science & Engineering

B.Tech-CS&IT-VI-Sem
Sub : System Software Engineering

Graded Assignment-2

Name :- Mukesh Kumar Enroll. No.: - CP10101408698

Q1 What is assembler? Explain it’s machine dependent and independent


features. Make one pass assembler.
Ans:-

Assembly language is converted into executable machine code by a utility


program referred to as an assembler; the conversion process is referred to as
assembly, or assembling the code. Assembly language uses a mnemonic to
represent each lowlevel machine instruction or operation.

An assembler is a program that takes basic computer instructions and converts


them into a pattern of bits that the computer's processor can use to perform its
basic operations. Some people call these instructions assembler language and
others use the term assembly language.

An assembler is a type of computer program that interprets software programs


written in assembly language into machine language, code and instructions that
can be executed by a computer.
An assembler enables software and application developers to access, operate
and manage a computer's hardware architecture and components.
An assembler is sometimes referred to as the compiler of assembly language. It
also provides the services of an interpreter.

Machine-Dependent features Of Assembler :-


1) Literal
2) Symbol
3) Expression

March 21, 2017 1


4) Immediate addressing
a. The operand value is assembled as part of the machine instruction.
5) Literal
a. The assembler generates the specified value as a constant at some
other memory location.
b. The address of this generated constant is used as the target address
for the machine instruction.
c. The effect of using a literal is exactly the same as if the
programming had defined the constant explicitly and used the label
assigned to the constant as the instruction operand.
6) All of the literal operands used in the program are gathered together into
one or more literal pools.
7) Normally literals are placed into a pool at the end of the program.
8) Sometimes, it is desirable to place literals into a pool at some other
location in the object program.
a. LTORG directive is introduced for this purpose.
b. When the assembler encounters a LTORG, it creates a pool that
contains all of the literals used since the previous LTORG.
9) If we do not use a LTORG on line 93, the literal =C’EOF’ will be placed
at the end of the program.
10) This operand will then begin at address 1073 and be too far away
from the instruction that uses it. PC-relative addressing mode cannot be
used.

LTORG thus is used when we want to keep the literal operands close to the
instruction that uses it
Machine-Independent features Of Assembler :-

– Literals
– Symbol-defining statements
– Expressions
– Program blocks
– Control sections and program linking

SIC/XE Instruction Formats and Addressing Modes

• PC-relative or Base-relative (BASE directive needs to be used)


addressing: op m
• Indirect addressing: op @m
• Immediate addressing: op #c
• Extended format (4 bytes): +op m

March 21, 2017 2


• Index addressing: op m,X
• Register-to-register instructions

• PC-relative or base-relative addressing mode is preferred over direct


addressing mode.
– Can save one byte from using format 3 rather than format 4.
• Reduce program storage space
• Reduce program instruction fetch time
– Relocation will be easier.
• Register-to-register instructions are used whenever possible to improve
execution speed.
– Fetch a value stored in a register is much faster than fetch it from
the memory.
• Immediate addressing mode is used whenever possible.
– Operand is already included in the fetched instruction. There is no
need to fetch the operand from the memory.
• Indirect addressing mode is used whenever possible.

ONE PASS ASSEMBLER:-

March 21, 2017 3


Q2 Define the different types of pass structure of Assembler.
Ans:-

The functions of the two passes assembler.



Pass 1

Translate assembly language programs to object programs or machine


code is called an Assembler.

 One-pass assemblers are used when


o it is necessary or desirable to avoid a second pass over the source
program
o the external storage for the intermediate file between two passes is
slow or is inconvenient to use
 Main problem: forward references to both data and instructions
 One simple way to eliminate this problem: require that all areas be
defined before they are referenced.
o It is possible, although inconvenient, to do so for data items.
o Forward jump to instruction items cannot be easily eliminated.

Data structures for assembler:

Op code table
Looked up for the translation of mnemonic code

 key: mnemonic code


 result: bits

Hashing is usually used

 once prepared, the table is not changed


 efficient lookup is desired
 since mnemonic code is predefined, the hashing function can
be tuned a priori

The table may have the instruction format and length

 to decide where to put op code bits, operands bits, offset bits


 for variable instruction size
 used to calculate the address

March 21, 2017 4


Symbol table
Stored and looked up to assign address to labels

 efficient insertion and retrieval is needed


 deletion does not occur

Difficulties in hashing

 non random keys

Problem

 the size varies widely

pass 1: loop until the end of the program


1. Read in a line of assembly code
2. Assign an address to this line

 increment N (word addressing or byte addressing)

3. Save address values assigned to labels

 in symbol tables

4. Process assembler directives

 constant declaration
 space reservation

Algorithm for Pass 1 assembler:

begin
if starting address is given
LOCCTR = starting address;
else
LOCCTR = 0;
while OPCODE != END do ;; or EOF
begin
read a line from the code
if there is a label
if this label is in SYMTAB, then error
else insert (label, LOCCTR) into SYMTAB
search OPTAB for the op code
if found
LOCCTR += N ;; N is the length of this instruction

March 21, 2017 5


(4 for MIPS)
else if this is an assembly directive
update LOCCTR as directed
else error
write line to intermediate file
end
program size = LOCCTR - starting address;
end

Load-and-go assembler

 Load-and-go assembler generates their object code in memory for


immediate execution.
 No object program is written out, no loader is needed.
 It is useful in a system oriented toward program development and testing
such that the efficiency of the assembly process is an important
consideration

Forward Reference:

o Load-and-go assembler
 Omits the operand address if the symbol has not yet been
defined
 Enters this undefined symbol into SYMTAB and indicates
that it is undefined
 Adds the address of this operand address to a list of forward
references associated with the SYMTAB entry
 Scans the reference list and inserts the address when the
definition for the symbol is encountered.
 Reports the error if there are still SYMTAB entries indicated
undefined symbols at the end of the program
 Search SYMTAB for the symbol named in the END
statement and jumps to this location to begin execution if
there is no error

 Assign addresses to all statements (generate LOC).


 Check the correctness of Instruction (check with OP table). ‰
 Save the values (address) assigned to all labels into SYMBOL table for
Pass 2.
 Perform some processing of assembler directives.

March 21, 2017 6


„ Pass 2
 ‰Assemble instructions (op code from OP table, address from SYMBOL
table)
 Generate data values defined by BYTE, WORD.
 Perform processing of assembler directives not done during Pass 1.

March 21, 2017 7

S-ar putea să vă placă și