0% found this document useful (0 votes)
320 views9 pages

Q 1. Discuss Design Specification of A Assembler With Diagram? Ans

An assembler converts assembly language mnemonics into machine-readable machine code. It performs a mostly one-to-one translation using a symbol table and mnemonic table in its synthesis phase. Relocation allows programs to be loaded into different memory locations by modifying address fields as needed based on the starting load address, so that symbolic references still point to the correct locations.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
320 views9 pages

Q 1. Discuss Design Specification of A Assembler With Diagram? Ans

An assembler converts assembly language mnemonics into machine-readable machine code. It performs a mostly one-to-one translation using a symbol table and mnemonic table in its synthesis phase. Relocation allows programs to be loaded into different memory locations by modifying address fields as needed based on the starting load address, so that symbolic references still point to the correct locations.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Part A

Q 1. Discuss design specification of a assembler with diagram?


Ans- It is designed to convert symbolic instruction into a form suitable for
execution on a computer. It is also known as assembly program; assembly routine.
Contrast with compiler, which is used to translate a high an assembler is used to
translate assembly language statements into the target computers machine code.
The assembler performs a more or less isomorphic translation a one-to-one
mapping from mnemonic.
We use a four step approach to develop specification for an assembler .
1-identify the information necessary to perform a task.
2-design a suitable data structure to record the information.
3-determine the processing necessary to perform the task.
4-determine the processing necessary to obtain and maintain the information.

Synthesis phase:-
Two data structure are used in synthesis phas:-
1-symbol table
2-mneomonics table.
Q 2. How a assembler converts mnemonic code in to machine understandable
form? Explain?()()()()()(figers)

Ans The machine language consists of 0’s and 1’s and also Mnemonic
Codes(Assembly Languages).

In machine languages, the execution time is very less compare to other languages
because; the computer can understand instructions in code form. This machine languages
are difficult in nature.

In Assembly language, mnemonic codes were used instead of 0’s and 1’s used in
machine language.

Here each machine instruction is represented by meaningful mnemonics such as


ADD, SUB MUL, DIV and data are specified.

Here translator is needed to convert assembly language into machine language. Hence
assembler is used.

Compare to machine language, it gives little more readability, and also easy to modify
and isolate errors.

Assembler uses the translator program for conversion through mnemonics code
into machine language.

Q 3. What are various types of assemblers which can be developed?


Ans- Assembly languages are a type of low-level languages for programming computers,
microprocessors, microcontrollers, and other (usually) integrated circuits. They
implement a symbolic representation of the numeric machine codes and other constants
needed to program a particular CPU architecture. This representation is usually defined
by the hardware manufacturer, and is based on abbreviations (called mnemonics) that
help the programmer remember individual instructions, registers, etc. An assembly
language family is thus specific to a certain physical (or virtual) computer architecture.
This is in contrast to most high-level languages, which are (ideally) portable.
A utility program called an assembler, is used to translate assembly language statements
into the target computer's machine code. The assembler performs a more or less
isomorphic translation (a one-to-one mapping) from mnemonic statements into machine
instructions and data. This is in contrast with high-level languages, in which a single
statement generally results in many machine instructions.
Many sophisticated assemblers offer additional mechanisms to facilitate program
development, control the assembly process, and aid debugging. In particular, most
modern assemblers include a macro facility (described below), and are called macro
assemblers.

Assembler
Typically a modern assembler creates object code by translating assembly instruction
mnemonics into opcodes, and by resolving symbolic names for memory locations and
other entities. The use of symbolic references is a key feature of assemblers, saving
tedious calculations and manual address updates after program modifications. Most
assemblers also include macro facilities for performing textual substitution—e.g., to
generate common short sequences of instructions as inline, instead of called subroutines,
or even generate entire programs or program suites.

Assembly language Assembler


Assembler machine language and other
Program information for the loader

Data bases

Assemblers are generally simpler to write than compilers for high-level languages, and
have been available since the 1950s. Modern assemblers, especially for RISC based
architectures, such as MIPS, Sun SPARC, and HP PA-RISC, as well as x86(-64),
optimize instruction scheduling to exploit the CPU pipeline efficiently.

Types of assembler:-

There are two types of assemblers based on how many passes through the source are
needed to produce the executable program.
One-pass assemblers go through the source code once and assumes that all symbols will
be defined before any in
struction that references them.
Two-pass assemblers (and multi-pass assemblers) create a table with all unresolved
symbols in the first pass, then use the 2nd pass to resolve these addresses. The advantage
of a one-pass assembler is speed, which is not as important as it once was with advances
in computer speed and capabilities. The advantage of the two-pass assembler is that
symbols can be defined anywhere in the program source. As a result, the program can be
defined in a more logical and meaningful way. This makes two-pass assembler programs
easier to read and maintain.
More sophisticated high-level assemblers provide language abstractions such as:
Advanced control structures
High-level procedure/function declarations and invocations
High-level abstract data types, including structures/records, unions, classes, and sets
Sophisticated macro processing (although available on ordinary assemblers since late
1960s for IBM/360, amongst other machines)
Object-Oriented features such as encapsulation, polymorphism, inheritance, interfaces
Assembler Developed-Many sophisticated assemblers offer additional
mechanisms to facilitate program development, control the assembly process, and
aid debugging. In particular, most modern assemblers include a macro facility
(described below), and are called macro assemblers.

Q 4. Assembler can perform operations of search and sort? Give your comments?
ANSWER:

Searching and Sorting:

It is often necessary to maintain large tables of information in such a way that


items may be moved in and out quickly and easily. Let us consider the restricted
case of a table whose entries are made on the basis of keyword, such as the
symbol table maintained by a assembly program.

The assembler symbol table is composed of multiple-word entries in a fixed


format. In the table is the symbol name, its value and various attributes such as
relocability. The symbol name is the key, the string distinguishing each entry
from the others that is matched during a search. Each symbol has a corresponding
location, its value.

It finds the maximum number and this can help you write the sort program

LXI H,ADD1

; Load 16 bit data in reg pair H

MOV C,M

; Load the counter to compare the total no of data to count

INX H

; Increment the address to point to the next location

MOV A,M

; Load the second no in the accumulator

ADD2:

; Label to jump at

INX H
; Increment the address to point to the next location

CMP M

; Compate the accumulator with the next no in series

JNC LESS:

; Jmp to a location with the comparision returns a carry

MOV A,M

; Move the content of the location M into the accumulator if the Jump
fails

LESS:

; Label to jump at

DCR C

; decrement the counter

JNZ ADD2

; Jump if there is anything more to compare

STA ADD_OUTPUT

; Accumulator will contain the Max no and move to the out put address.

Part B
Q1. What is the need for relocation of the program? With an example explain how
relocation can be done.
Ans- Program Relocation:
It is often desirable to have more than one program at a time sharing the
memory and other resources of machine. If we knew in advance exactly
which programs were to be executed concurrently in this way, we could
assign addresses when the programs were assembled so that they could fit
together without overlap or wasted space. Most of the time, however, it is
not practical to plan program execution this closely. Because of this, it is
desirable to be able to load a program into memory whenever there is
room for it. In such cases, the actual starting address of the program is
known until load time.
Since the assembler does not know the actual location where the program
will be loaded, it cannot make the necessary changes in the address used
by the program. However, the assembler can identify for the loader those
parts of the object program that needs modification. An object program
that contains necessary information to perform this kind of modification is
called relocation program.
Example-
how a program is loaded, beginning at address 0000.JSUB instruction is loaded at
address 0006. Consider that the address field of this instruction contains 01036,
which is the address of the instruction labeled RDREC. Now suppose we want to
load this program beginning at address 5000 as shown in fig 2. The address of this
instruction labeled RDREC is then 6036.
Thus the JSUB instruction must be modified as shown to contain this new
address. Likewise, if we loaded the program beginning at address 7420
(fig 3), the JSUB instruction would need to be changed to 4b108456 to
correspond to the new address of RDREC.
1. When the assembler generates the opcode for JSUB, we are considering, it will
insert the address RDREC relative to the start of the program.
2. The assembler will also produce a command for the loader, instructing it to add
the beginning address of the program to the address field in the JSUB instruction
at the load time.

(+JSUB RDREC) (+JSUB RDREC)


0000 . 5000 .
. . . .
. .
0006 4B101036 RDREC 5006 4B101036
. . . . RDREC
. . . .
1036 B410 6036 B410
. . .
. . .
.1076 . 6076

Fig(1) Fig(2)

(+JSUB RDREC)
7420 .
. .
. .
.7426 4B101036
. .
. .
8456 B410 RDREC
. .
. .
. .
8496 .
Q2. Enlist the various assembler features that are machine dependent and machine
independent. Explain any one of them from each.
Ans- Using an intermediate language is a well-known, effective technique for
constructing interpreters and compilers. This paper describes a retargetable,
optimizing compilation system centered around the use of two intermediate
languages (IL): one relatively high level, the other a low level corresponding to
target machine instructions. The high-level IL (HIL) models a stack-based,
hypothetical RISC machine. The low-level IL (LIL) models target machines at the
instruction-set architecture level. All code improvements are applied to the LIL
representation of a program. This is motivated by the observation that most
optimizations are machine dependent, and the few that are truly machine
independent interact with the machine-dependent ones. This paper describes
several machine-independent code improvements and shows that they are actually
machine dependent. To illustrate how code improvements can be applied to a LIL,
an algorithm for induction variable elimination is presented. It is demonstrated that
this algorithm yields better code than traditional implementations that are applied
machine-independently to a high-level representation.

Q3. What are the basic functions of a loader? Develop an algorithm for a bootstrap
loader.
Ans-

Functions of loader:

• bringing an object program into memory


• starting its execution
• The loader is capable of loading modules in a range of object formats, and
knowledge of these formats is built in to the loader.
• Knowledge of new object formats can be added to the loader in a straightforward
manner. This makes it possible to provide OS-independent modules (for a given
CPU architecture type).
• In addition to this, the loader can load modules via the OS-provided dlopen(3)
service where available. Such modules are not platform independent, and the
semantics of dlopen() on most systems results in significant limitations in the
use of modules of this type. Support for dlopen() modules in the loader is
primarily for experimental and development purposes.
• A loader is a system program that performs the loading function.

– many also support relocation & linking


– others have a separate linker and loader

• A single loader and linker exist on a system since compilers/assemblers produce


object code in the same format.
• A more complex loader– suitable for SIC/XE and is typical of those found on
most modern computers that supports relocation and linking

Algorithm for bootstrap loader:

The software begins by checking for the signal to start the loader. If present, the
device performs user-requested boot-loader functions. When complete, or if no
loader stimulus was detected, the device will jump to location FFF0h, modify the
ROMSIZE register to disable internal EPROM, and jump back to the restart
vector. This simulates a device beginning execution at address 0000h following a
reset.

Q4. What is machine dependent loader? Explain its features.


Ans- Relocation
Loaders that allow for program relocation are called relocating loaders or relative
loaders.
The need for program relocation is a consequence of the change to larger and
more powerful computers.
We would like to run several programs on a more advanced machine.
Schemes for relocation
Modification record
• A modification record is used to describe each part of
the object code that must be changed when the
program is relocated.
� Relocation bit
• A relocation bit associated with each word of object
code is used to indicate whether or not this word
should be changed when the program is relocated.
� Hardware relocation
• Some computers provide a hardware relocation
capability that eliminates some of the need for the
loader to perform program relocation.

You might also like