Cdss Assignment 2
Cdss Assignment 2
ASSIGNMENT 2
SUBJECT: CDSS
An assembler is a program that converts assembly language into machine code. It takes the basic
commands and operations from assembly code and converts them into binary code that can be recognized
by a specific type of processor.
Assemblers are similar to compilers in that they produce executable code. However, assemblers are more
simplistic since they only convert low-level code (assembly language) to machine code. Since each
assembly language is designed for a specific processor, assembling a program is performed using a simple
one-to-one mapping from assembly code to machine code. Compilers, on the other hand, must convert
generic high-level source code into machine code for a specific processor.
Most programs are written in high-level programming languages and are compiled directly to machine
code using a compiler. However, in some cases, assembly code may be used to customize functions and
ensure they perform in a specific way. Therefore, IDEs often include assemblers so they can build
programs from both high and low-level languages.
Linker:
For most compilers, each object file is the result of compiling one input source code file. When a program
comprises multiple object files, the linker combines these files into a unified executable program,
resolving the symbols as it goes along.
Some linkers do not include the whole library in the output they only include its symbols that ale
referenced from other object files or libraries. Libraries exist for diverse purposes, and one or more
system libraries are usually linked in by default.
The linker also takes care of arranging the objects in a program’s address space. This may involve
relocating code that assumes a specific base address to another base. Since a compiler seldom knows
where an object will reside, it often assumes a fixed base location (for example, zero). Relocating machine
code may involve targeting of absolute jumps, loads and stores
loader
ALLOCATION: it allocates the space for program in the memory, by calculating the size of the program.
LINKING: it resolves the symbolic references (code/data) between the object modules by assigning all
the user subroutine and library subroutine addresses.
RELOCATION: There are some address dependent locations in the program such as address constants
must be adusted acording to allocated space such activity done by loader.
LOADING:finally it places the machine instructions and data of corresponding programs and subroutines
into the memory. Thus program now becomes ready for execution
Absolute loader
Absolute Loader is a kind of loader in which relocated object files are created, loader accepts these files
and places them at specified locations in the memory. This type of loader is called absolute because no
relocation information is needed rather it is obtained from the programmer or assembler.
The starting address of every module is known to the programmer this corresponding address is stored in
the object file, then task of loader becomes very simple and that is to simply place the executable form of
the machine instructions at the locations mentioned in the object file.
LOADERS
If some modification is done in some module then the length of that module may vary.
This causes a change in the starting address of immediate next modules, its then programmer duty to
make necessary changes in the starting addresses of respective modules.
Second, while branching from one segment to another the absolute starting address of respective
module is to be known by the programmer so that such address can be specified at respective JMP
instruction.
Header record
Text record
End record
The absolute loader accepts this object module from assembler and by reading the information about the
starting address, it will place the subroutine at specified address in the memory.
Memory
Locations CONTENT
0010
1010
:
2030 xxxxxxxx xxxxxxxx XX041030 001030E0
The object code is divided into 1byte(hex notation) at one mem locations
1000- 14
1001 10
1002 33
1003 48
100F->48
Bootstramp loader
When a computer is first turned on or restarted, a special type of absolute loader,called bootstrap loader is
executed. This bootstrap loads the first program to be run by the computer -- usually an operating system.
The bootstrap itself begins at address 0. It loads the OS starting address 0x80. No header record or control
information, the object code is consecutive bytes of memory.
The bootstrap loader is a small program and it should be fitted in the ROM.
The bootstrap loader must load the necessary portions of OS in the main memory
The initial address at which the bootstrap loader is to be loaded is generally the lowest for example at
location 0000 or at the highest location and not a intermediate location.
Begin
BOOT START 0
CLEAR A
LOOP JSUB GETC //read hex digit from program being loaded
JLT RETURN
RETURN RSUB
END LOOP
if A
ELSE
A A-48 (0x30)
if A
ELSE
A A-7
return
Absolute loader is simple and efficient, but the scheme has potential disadvantages One of the most
disadvantage is the programmer has to specify the actual starting address, from where the program to be
loaded. This does not create difficulty, if one program to run, but not for several programs. Further it is
difficult to use subroutine libraries efficiently.
This needs the design and implementation of a more complex loader. The loader must provide program
relocation and linking, as well as simple loading functions.
Relocation
The concept of program relocation is, the execution of the object program using any part of the available
and sufficient memory. The object program is loaded into memory wherever there is
room for it. The actual starting address of the object program is not known until load time. Relocation
provides the efficient sharing of the machine with larger memory and when several independent programs
are to be run together. It also supports the use of subroutine libraries efficiently. Loaders that allow for
program relocation are called relocating loaders or relative
loaders.
There are two methods for specifying relocation as a part of object program and those are
1. Modification record:
a. For small number of relocation this method is useful. This method is used for
Col 1: M
Col 2-7 Starting location of the address field to be modified relative to the beginning
of the program(hexadecimal)
COPY START 0
:::::
:::::
LOADERS
:::::
:::::
OBJECT PROGRAM
H^COPY ^000000^001077
T^000000^1D^17202D^69202D……..
M^000007^05+COPY
M^000014^05+COPY
M^000027^05+COPY
E^000000
Disadvantage:This method is not well suited for SIC program . because these programs will
require lot of modified records and then the size of object program will get increased.
2. RELOCATION BITS The relocation bit method is used for simple machines.
Text record
col 1: T
Twelve-bit mask is used in each Text record (col:10-12 – relocation bits), since each text record
contains less than 12 words, unused words are set to 0, and, any value that is to be modified
during relocation must coincide with one of these 3-byte segments. For absolute loader, there are
no relocation bits column 10-69 contains object code. The object program with relocation by bit
mask is as shown below. Observe FFC - means all ten words are to be modified and, E00 -
LOADERS
Page 7
For example :
T^000000^1E^FFE^140033^481039…………………….^00002D
T^00001E^15^0C0036…………^000000
T^00001E^15^E00^0C0036…………^000000
3. explain about single pass,two pass and multi pass assembler with code example
and object file
Multi_Pass Assembler:
For a two pass assembler, forward references in symbol definition are not allowed:
DELTA RESW 1
When a symbol is defined, we can recursively evaluate the symbol expressions depending on the
newly defined symbol.
ALGORITHM:
begin
begin
begin
begin
if found then
begin
the linked list with the corresponding operand PTR addresses and generated operand
set symbol value as LOCCTR in symbol table and delete the linked list
end
else
end
if found then
begin
if found then
else
add 3 to LOCCTR
end
UNIT 2: ASSEMBLER
begin
end
if object code will not fit into current text record then
begin
end
end
end
write last text record to object program
end{Pass 1}
The LTORG directive instructs the assembler to assemble the current literal pool immediately.
Syntax
LTORG
Usage
The assembler assembles the current literal pool at the end of every code section. The end of a code
section is determined by the AREA directive at the beginning of the following section, or the end of the
assembly.
These default literal pools can sometimes be out of range of some LDR, VLDR,
and WLDR pseudo-instructions. Use LTORG to ensure that a literal pool is assembled within range.
Large programs can require several literal pools. Place LTORG directives after unconditional branches or
subroutine return instructions so that the processor does not attempt to execute the constants as
instructions.
The assembler word-aligns data in literal pools.
EQU - The equate directive is used to substitute values for symbols or labels. The format is 'label: EQU
value', so whenever the assembler encounters 'label', it replaces this with 'value'. This is especially handy
for improving program readability. For instance, we could write 'ldx #$0032', or we could use 'portb:
EQU $0032' followed later by 'ldx #portb'. The latter 'ldx' instruction is more readable than the former.
The EQU directive only tells the assembler to substitute a value for a symbol or label, and doesn't involve
any type of ROM or RAM. EQU directives are typically placed at the beginning of an assembly program.
Examples:
The Operation code Table must contain the mnemonic operation code and its machine language
equivalent. In more complex assembles , this table also contains information about instruction format and
length.During Pass 1 , OPTAB is used to look up and validate opearation coded in the source program. In
pass 2 , it is used to translate the operation codes to machine language. Actually , in our simple SIC
assembler , both of these processes could be done together in either PASS 1 or PASS 2. However , for a
machine that has instructions of different lengths, we must search OPTAB in the first pass to find the
instructions length for incrementing LOCCTR. Likewise , we must have the information from OPTAB is
PASS 2 to tell us which instruction format to use in assembling the instruction ,and my peculiarities of the
object code instruction. We have chosen to retain this structure in the current discussion because it is
typical of most real assembles.
5.
1. Explain difference between 1 pass Assembler and load and go assembler.
A one pass assembler passes over the source file exactly once, in the same pass collecting the labels,
resolving future references and doing the actual assembly. The one pass assembler prepares an
intermediate file, which is used as input by the go assembler.
Indirect Mode
The effective address of the operand is the contents of a register or main memory location,
location whose address appears in the instruction. Indirection is noted by placing the
name of the register or the memory address given in the instruction in parentheses. The
register or memory location that contains the address of the operand is a pointer. When an
execution takes place in such mode, instruction may be told to go to a specific address.
Once it's there, instead of finding an operand, it finds an address where the operand is
located.
Immediate Mode
The operand is an immediate value is stored explicitly in the instruction: Example: SPIM
( opcode dest, source)
li $11, 3 // loads the immediate value of 3 into register $11 li $9, 8 // loads the immediate
value of 8 into register $9
Example : (textbook uses instructions type like, opcode source, dest) move #200, R0; //
move immediate value 200 in register R0
Index Mode
The address of the operand is obtained by adding to the contents of the general register
(called index register) a constant value. The number of the index register and the constant
value are included in the instruction code. Index Mode is used to access an array whose
elements are in successive memory locations. The content of the instruction code,
represents the starting address of the array and the value of the index register, and the
index value of the current element. By incrementing or decrementing index register
different element of the array can be accessed.
The assembler assembles the data item specified in a literal into a literal pool, The literals
processed by the assembler are collected and placed in a special area called the literal pool.
You can control the positioning of the literal pool. Unless otherwise specified, the literal
pool is placed at the end of the first control section.
A.\