0% found this document useful (0 votes)
5 views

SS Unit-1

Sscd

Uploaded by

chethanrohit0045
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SS Unit-1

Sscd

Uploaded by

chethanrohit0045
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

SS&CD [CS506] PART A - UNIT 1

Machine Architecture
Definition of Software:
Software is a set of programs, which is assigned to perform a well defined function. A
program is a sequence of instructions written to solve a particular problem.

Types of Software:

1. System Software.
2. Application Software.

Definition of System Software:


System software consists of variety of programs that support the operation of a
computer.

Eg: text editor, compiler, loader and linker, debugger, macro processors, operating
system etc...
Text Editor: Used to create and modify program.
Compiler: Translate the user program into machine language.
Loaders: Is a system programs that prepare machine language programs for execution.
Debugger: Helps to detect errors in the program.
Translator: Used to translate the assembly code into machine code. This translator is
called an assembler.

User

Application Program

Debugger Macro Processor Text Editor Utility


Program(library)

Complier Assembler Loader and Linker

OS
Memory Process Device Information
Management Management Management Management

Computer
Fig: System Software Concept

DEPARMENT OF CSE, MCE Page 1


SS&CD [CS506] PART A - UNIT 1

Difference between System Software and Application Software

System Software Application Software


Collection of programs that help the user Collection of program written for a
to interact with hardware components specific application such as payroll
efficiently. banking, reservation of tickets etc..
System Software control and manage Application software uses the services of
the hardware. the system software to interact with
hardware components.

To write system software the To write the application software the


programmer needs to understand the programmer need not worry about the
architecture and hardware details and architecture and hardware details and
hence are machine dependent. hence are machine independent.
Directly interact with hardware. Interact with hardware using system calls
provided by various system software.
application software will not directly
interact with hardware.
Development of system software is Development of application software is
difficult task. relatively easier.

Eg: Complier, Assembler, Operating Eg: Payroll, Microsoft word, Excel etc...
system etc..

Simplified Instructional Computer(SIC)


SIC is a hypothetical computer that has been carefully designed to include the
hardware features most often found on real machine.
SIC machine comes in two versions:
1. SIC(standard mode)
2. SIC/XE(XE=extra equipment)
Both the versions are upward compatible, i.e. a for standard SIC machine also
execute properly on the other versions of the SIC/XE machine.

SIC Machine Architecture:

Memory:
 Upward compatible
 Memory consists of 8-bit bytes, 3 consecutive bytes form a word (24 bits)
 There are a total of 215=32768 bytes in the computer memory.

DEPARMENT OF CSE, MCE Page 2


SS&CD [CS506] PART A - UNIT 1

Registers:
5 registers, 24 bits in length

Data Format:
 Integers are stored as 24-bit binary number.
 2’s complement representation for negative values.
 Characters are stored using 8-bit ASCII codes.
 No floating-point hardware on the standard version of SIC.

Instruction Format:

 24-bit format.
 The flag bit x is used to indicate indexed-addressing mode.

Addressing Modes:

There are two addressing modes available:

1. Direct Addressing mode.


2. Indexed Addressing mode.
 Indicated by x bit in the instruction
(X) represents the contents of reg. X

DEPARMENT OF CSE, MCE Page 3


SS&CD [CS506] PART A - UNIT 1

Instruction Set:

 Load and store registers (LDA, LDX, STA, STX, etc.)


 Integer arithmetic operations (ADD, SUB, MUL, DIV)
Register A is involved in all arithmetic operations and a word in memory.
Results is stored in the register.
 Compare instruction (COMP)
It compares the register A value with a word in memory.
 Conditional jump instructions (JLT, JEQ, JGT)
All the above instructions can test the setting of a conditional code and jump
accordingly.
 JSUB jumps to the subroutine, placing the return address in register L.
 RSUB returns by jumping to the address contained in register L.

Input and Output:

 I/O are performed by transferring 1 byte at a time to or from the rightmost 8


bits of register A.
 Each device is assigned a unique 8-bit code as an operand.
 Test Device (TD): tests whether the addressed device is ready to send or
receive.
 < ready = not ready
A program needing to transfer data must wait until device is ready, then
execute read data and write data.
 Read Data (RD)
 Write Data (WD)

SIC/XE Machine Architecture

XE stands for Extra Equipment

Memory:

 Memory consists of 8-bit bytes, 3 consecutive bytes form a word (24 bits).
 Maximum memory available on a SIC/XE system is 1 Megabyte (220 bytes)

Registers:

Additional B, S, T, and F registers are provided by SIC/XE, in addition to the


registers of SIC.

DEPARMENT OF CSE, MCE Page 4


SS&CD [CS506] PART A - UNIT 1

Data Formats:
 24-bit binary number for integer, 2’s complement for negative values.
 48-bit floating-point data type.
 The exponent is between 0 and 2047.
 f*2(e-1024)
 0: set all bits to 0

1 11 36
s exponent fraction

Instruction Format:

It consists of four Different types of format.

Format 1(1 byte): 8 bit


op

Format 2 (2 bytes) :
8 4 4
op r1 r2

Formats 1 and 2 are instructions do not reference memory at all

Format 3 (3 bytes): 6 1 1 1 1 1 1 12
op n i x b p e disp
Here e=0

Format 4 (4 bytes): 6 1 1 1 1 1 1 20

Here e=1 op n i x b p e address

Addressing Modes:
n i x b p e
Simple n=0, i=0 (SIC) or n=1, i=1
Immediate n=0, i=1 TA=Valus
Indirect n=1, i=0 TA=(Operand)

DEPARMENT OF CSE, MCE Page 5


SS&CD [CS506] PART A - UNIT 1

Base relative b=1, p=0 TA=(B)+disp 0 <= disp <= 4095


PC relative b=0, p=1 TA=(PC)+disp -2048 <= disp <= 2047

Direct (x, b, and p all set to 0): operand address goes as it is. n and i are both set to the
same value, either 0 or 1. While in general that value is 1, if set to 0 for format 3 we
can assume that the rest of the flags (x, b, p, and e) are used as a part of the address of
the operand, to make the format compatible to the SIC format.

Relative (either b or p equal to 1 and the other one to 0): the address of the operand
should be added to the current value stored at the B register (if b = 1) or to the value
stored at the PC register (if p = 1)

Immediate (i = 1, n = 0): The operand value is already enclosed on the instruction (ie.
lies on the last 12/20 bits of the instruction)

Indirect (i = 0, n = 1): The operand value points to an address that holds the address
for the operand value.

Indexed (x = 1): value to be added to the value stored at the register x to obtain real
address of the operand. This can be combined with any of the previous modes except
immediate.

The various flag bits used in the above formats have the following meanings e i.e e =
0 means format 3, e = 1 means format 4
Bits x,b,p: Used to calculate the target address using relative, direct, and indexed
addressing Modes
Bits i and n: Says, how to use the target address b and p - both set to 0, disp field from
format 3 instruction is taken to be the target address. For a format 4 bits b and p are
normally set to 0, 20 bit address is the target address.
x - x is set to 1, X register value is added for target address calculation

Instruction Set:
 Format 1, 2, 3, or 4
 Load and store registers (LDB, STB, etc.)
 Floating-point arithmetic operations (ADDF, SUBF, MULF, DIVF)
 Register-to-register arithmetic operations (ADDR, SUBR, MULR, DIVR)
 A special supervisor call instruction (SVC) is provided

Input and Output:


 1 byte at a time, TD, RD, and WD
 SIO, TIO, and HIO are used to start, test, and halt the operation of I/O
channels.

DEPARMENT OF CSE, MCE Page 6


SS&CD [CS506] PART A - UNIT 1

SIC and SIC/XE Programming examples:

Example 1: Simple data and character movement operation

Example 2: Arithmetic operations

SIC VERSION

DEPARMENT OF CSE, MCE Page 7


SS&CD [CS506] PART A - UNIT 1

SIC/XE VERSION

Example 3: Looping and Indexing operation


SIC VERSION

DEPARMENT OF CSE, MCE Page 8


SS&CD [CS506] PART A - UNIT 1

SIC/XE VERSION

Example 4: Indexing and Looping operation

SIC VERSION

DEPARMENT OF CSE, MCE Page 9


SS&CD [CS506] PART A - UNIT 1

SIC/XE VERSION

Example 5: Input and Output operation

SIC VERSION

DEPARMENT OF CSE, MCE Page 10


SS&CD [CS506] PART A - UNIT 1

Subroutine operation

SIC

SIC/XE

Example to Calculate target address:

DEPARMENT OF CSE, MCE Page 11


SS&CD [CS506] PART A - UNIT 1

ASSEMBLER

Assembler is system software which is used to convert an assembly language program


to its equivalent object code. The input to the assembler is a source code written in
assembly language (using mnemonics) and the output is the object code. The design of
an assembler depends upon the machine architecture as the language used is mnemonic
language.
The Basic assembler functions are:
 Translating mnemonic language code to its equivalent object code.
 Assigning machine addresses to symbolic labels.

The design of assembler can be to perform the following:


o Scanning (tokenizing)
o Parsing (validating the instructions)
o Creating the symbol table
o Resolving the forward references
o Converting into the machine language
The design of assembler in other words:
 Convert mnemonic operation codes to their machine language equivalents
 Convert symbolic operands to their equivalent machine addresses

DEPARMENT OF CSE, MCE Page 12


SS&CD [CS506] PART A - UNIT 1

 Decide the proper instruction format Convert the data constants to internal
machine representations
 Write the object program and the assembly listing

So for the design of the assembler we need to concentrate on the machine architecture
of the SIC/XE machine. We need to identify the algorithms and the various data
structures to be used. According to the above required steps for assembling the
assembler also has to handle assembler directives, these do not generate the object
code but directs the assembler to perform certain operation.
The following are the assembler directives:
START :
• Specify name and starting address for the program
END :
• Indicate the end of the source program, and (optionally) the first
executable instruction in the program.
BYTE :
• Generate character or hexadecimal constant, occupying as many
bytes as needed to represent the constant.
WORD :
• Generate one-word integer constant
RESB :
• Reserve the indicated number of bytes for a data area
RESW :
• Reserve the indicated number of words for a data area
The assembler design can be done:
Single pass assembler
Multi-pass assembler
Single-pass Assembler:
In this case the whole process of scanning, parsing, and object code conversion is
done in single pass. The only problem with this method is resolving forward
reference.
This is shown with an example below:
10 1000 FIRST STL RETADR 141033
--
--
--
--
95 1033 RETADR RESW 1
In the above example in line number 10 the instruction STL will store the linkage
register with the contents of RETADR. But during the processing of this instruction
the value of this symbol is not known as it is defined at the line number 95. Since I
single pass assembler the scanning, parsing and object code conversion happens
simultaneously. The instruction is fetched; it is scanned for tokens, parsed for syntax
and semantic validity. If it valid then it has to be converted to its equivalent object
code. For this the object code is generated for the opcode STL and the value for the
symbol RETADR need to be added, which is not available. Due to this reason usually
the design is done in two passes. So a multi-pass assembler resolves the forward
references and then converts into the object code. Hence the process of the multi-pass
assembler can be as follows:

DEPARMENT OF CSE, MCE Page 13


SS&CD [CS506] PART A - UNIT 1

Pass-1
 Assign addresses to all the statements
 Save the addresses assigned to all labels to be used in Pass-2
 Perform some processing of assembler directives such as RESW, RESB to find
the length of data areas for assigning the address values.
 Defines the symbols in the symbol table(generate the symbol table)
Pass-2
 Assemble the instructions (translating operation codes and looking up
addresses).
 Generate data values defined by BYTE, WORD etc.
 Perform the processing of the assembler directives not done during pass-1.
 Write the object program and assembler listing.
Assembler Design:
 The most important things which need to be concentrated is the generation of
 Symbol table and resolving forward references.
Symbol Table:
 This is created during pass 1
 All the labels of the instructions are symbols
 Table has entry for symbol name, address value.
Forward reference:
 Symbols that are defined in the later part of the program are called
forward referencing.
 There will not be any address value for such symbols in the symbol
table in pass 1.
Example Program:
 The example program considered here has a main module, two
subroutines
Purpose of example program
 Reads records from input device (code F1)
 Copies them to output device (code 05)
 At the end of the file, writes EOF on the output device, then RSUB to
the operating system
Data transfer (RD, WD)
 A buffer is used to store record
 Buffering is necessary for different I/O rates
 The end of each record is marked with a null character (00)16
 The end of the file is indicated by a zero-length record
Subroutines (JSUB, RSUB)
 RDREC, WRREC
 Save link register first before nested jump

SIC PROGRAM

DEPARMENT OF CSE, MCE Page 14


SS&CD [CS506] PART A - UNIT 1

DEPARMENT OF CSE, MCE Page 15


SS&CD [CS506] PART A - UNIT 1

The first column shows the line number for that instruction, second column shows the
addresses allocated to each instruction. The third column indicates the labels given to
the statement, and is followed by the instruction consisting of opcode and operand. The
last column gives the equivalent object code.

Simple SIC Assembler:


The program below is shown with the object code generated. The column named LOC
gives the machine addresses of each part of the assembled program (assuming the
program is starting at location 1000).
The translation of the source program to the object program requires us to accomplish
the following functions:
1. Convert the mnemonic operation codes to their machine language equivalent.
2. Convert symbolic operands to their equivalent machine addresses.
3. Build the machine instructions in the proper format.
4. Convert the data constants specified in the source program into their internal
machine representations in the proper format.
5. Write the object program and assembly listing.

All these steps except the second can be performed by sequential processing of the
source program, one line at a time.
Consider the instruction
10 1000 LDA ALPHA 00-----
This instruction contains the forward reference, i.e. the symbol ALPHA is used is not
yet defined. If the program is processed (scanning and parsing and object code
conversion) is done line-by-line, we will be unable to resolve the address of this
symbol. Due to this problem most of the assemblers are designed to process the
program in two passes.

In addition to the translation to object program, the assembler has to take care of
handling assembler directive. These directives do not have object conversion but gives
direction to the assembler to perform some function.
Examples of directives are the statements like BYTE and WORD, which directs the
assembler to reserve memory locations without generating data values.

DEPARMENT OF CSE, MCE Page 16


SS&CD [CS506] PART A - UNIT 1

The other directives are START which indicates the beginning of the program and
END indicating the end of the program.
The assembled program will be loaded into memory for execution. The simple object
program contains three types of records: Header record, Text record and end
record. The header record contains the starting address and length. Text record
contains the translated instructions and data of the program, together with an indication
of the addresses where these are to be loaded. The end record marks the end of the
object program and specifies the address where the execution is to begin.

The format of each record is as given below:

Header record:
Col 1: H
Col 2-7: Program name
Col 8-13: Starting address of object program (hexadecimal)
Col 14-19: Length of object program in bytes (hexadecimal)

Text record:
Col. 1: T
Col 2-7: Starting address for object code in this record (hexadecimal)
Col 8-9: Length off object code in this record in bytes (hexadecimal)
Col 10-69: Object code, represented in hexadecimal (2 columns per byte of object
code)

End record:
Col. 1: E
Col 2-7: Address of first executable instruction in object program (hexadecimal)

The assembler can be designed either as a single pass assembler or as a two pass
assembler. The general description of both passes is as given below:
Pass 1 (define symbols)
 Assign addresses to all statements in the program
 Save the addresses assigned to all labels for use in Pass 2
 Perform assembler directives, including those for address assignment, such as
BYTE and RESW
Pass 2 (assemble instructions and generate object program)
 Assemble instructions (generate opcode and look up addresses)
 Generate data values defined by BYTE, WORD
 Perform processing of assembler directives not done during Pass 1
 Write the object program and the assembly listing

DEPARMENT OF CSE, MCE Page 17


SS&CD [CS506] PART A - UNIT 1

Algorithms and Data structure


The simple assembler uses two major internal data structures: the operation Code
Table (OPTAB) and the Symbol Table (SYMTAB).

OPTAB:

 It is used to lookup mnemonic operation codes and translates them to their


machine language equivalents. In more complex assemblers the table also
contains information about instruction format and length.
 In pass 1 the OPTAB is used to look up and validate the operation code in the
source program. In pass 2, it is used to translate the operation codes to machine
language. In simple SIC machine this process can be performed in either in
pass 1 or in pass 2. But for machine like SIC/XE that has instructions of
different lengths, we must search OPTAB in the first pass to find the
instruction length for incrementing LOCCTR.
 In pass 2 we take the information from OPTAB to tell us which instruction
format to use in assembling the instruction, and any peculiarities of the object
code instruction.
 OPTAB is usually organized as a hash table, with mnemonic operation code as
the key. The hash table organization is particularly appropriate, since it
provides fast retrieval with a minimum of searching. Most of the cases the
OPTAB is a static table- that is, entries are not normally added to or deleted
from it. In such cases it is possible to design a special hashing function or other
data structure to give optimum performance for the particular set of keys being
stored.

SYMTAB:
 This table includes the name and value for each label in the source program,
together with flags to indicate the error conditions (e.g., if a symbol is defined
in two different places).
 During Pass 1: labels are entered into the symbol table along with their
assigned address value as they are encountered. All the symbols address value
should get resolved at the pass 1.
 During Pass 2: Symbols used as operands are looked up the symbol table to
obtain the address value to be inserted in the assembled instructions.
 SYMTAB is usually organized as a hash table for efficiency of insertion and
retrieval. Since entries are rarely deleted, efficiency of deletion is the important
criteria for optimization.
 Both pass 1 and pass 2 require reading the source program. Apart from this an
intermediate file is created by pass 1 that contains each source statement
together with its assigned address, error indicators, etc. This file is one of the
inputs to the pass 2.
 A copy of the source program is also an input to the pass 2, which is used to
retain the operations that may be performed during pass 1 (such as scanning the
operation field for symbols and addressing flags), so that these need not be
performed during pass 2. Similarly, pointers into OPTAB and SYMTAB is
retained for each operation code and symbol used. This avoids need to repeat
many of the table-searching operations.

DEPARMENT OF CSE, MCE Page 18


SS&CD [CS506] PART A - UNIT 1

LOCCTR:
 Apart from the SYMTAB and OPTAB, this is another important variable
which helps in the assignment of the addresses.
 LOCCTR is initialized to the beginning address mentioned in the START
statement of the program.
 After each statement is processed, the length of the assembled instruction is
added to the LOCCTR to make it point to the next instruction. Whenever a
label is encountered in an instruction the LOCCTR value gives the address to
be associated with that label.

TWO PASS ASSEMBLER:

DEPARMENT OF CSE, MCE Page 19


SS&CD [CS506] PART A - UNIT 1

The Algorithm for Pass 1:


Begin
read first input line
if OPCODE = ‘START’ then
begin
save #[Operand] as starting addr
initialize LOCCTR to starting address
write line to intermediate file
read next line
end( if START)
else
initialize LOCCTR to 0
While OPCODE != ‘END’ do
begin
if this is not a comment line then
begin
if there is a symbol in the LABEL field then
begin
search SYMTAB for LABEL
if found then
set error flag (duplicate symbol)
else
insert(LABEL,LOCCTR)into SYMTAB
end{if Symbol}
earch OPTAB for OPCODE
if found then
add 3 (instr length) to LOCCTR
else if OPCODE = ‘WORD’ then
add 3 to LOCCTR
else if OPCODE = ‘RESW’ then
add 3 * #[OPERAND] to LOCCTR
else if OPCODE = ‘RESB’ then
add #[OPERAND] to LOCCTR
else if OPCODE = ‘BYTE’ then
begin
find length of constant in bytes
add length to LOCCTR
end
else
set error flag (invalid operation code)
end (if not a comment)
write line to intermediate file
read next input line
end { while not END}
write last line to intermediate file
Save (LOCCTR – starting address) as program lengt
End {pass 1}

DEPARMENT OF CSE, MCE Page 20


SS&CD [CS506] PART A - UNIT 1

Explanation:
 The algorithm scans the first statement START and saves the operand field (the
address) as the starting address of the program. Initializes the LOCCTR value
to this address. This line is written to the intermediate line. If no operand is
mentioned the LOCCTR is initialized to zero. If a label is encountered, the
symbol has to be entered in the symbol table along with its associated address
value.
 If the symbol already exists that indicates an entry of the same symbol already
exists. So an error flag is set indicating a duplication of the symbol.
 It next checks for the mnemonic code, it searches for this code in the OPTAB.
If found then the length of the instruction is added to the LOCCTR to make it
point to the next instruction.
 If the opcode is the directive WORD it adds a value 3 to the LOCCTR. If it is
RESW, it needs to add the number of data word to the LOCCTR. If it is BYTE
it adds a value one to the LOCCTR, if RESB it adds number of bytes.
 If it is END directive then it is the end of the program it finds the length of the
program by evaluating current LOCCTR – the starting address mentioned in
the operand field of the END directive. Each processed line is written to the
intermediate file.

The Algorithm for Pass 2:


Begin
read 1st input line from intermediate file
if OPCODE = ‘START’ then
begin
write listing line
read next input line
end
write Header record to object program
initialize 1st Text record
while OPCODE != ‘END’ do
begin
if this is not comment line then
begin
search OPTAB for OPCODE
if found then
begin
if there is a symbol in OPERAND field then
begin
search SYMTAB for OPERAND field
if found then
begin
store symbol value as operand
address
else
begin
store 0 as operand address
set error flag (undefined symbol)
end
end (if symbol)

DEPARMENT OF CSE, MCE Page 21


SS&CD [CS506] PART A - UNIT 1

else
store 0 as operand address assemble the object code
instruction
else if OPCODE = ‘BYTE’ or ‘WORD” then
convert constant to object code
if object code doesn’t fit into current Text record then
begin
Write text record to object code
initialize new Text record
end
add object code to Text record
end {if not comment}
write listing line
read next input line
end
write listing line
read next input line
write last listing line
End {Pass 2}

Explanation:
 Here the first input line is read from the intermediate file. If the opcode is
START, then this line is directly written to the list file. A header record is
written in the object program which gives the starting address and the length of
the program (which is calculated during pass 1). Then the first text record is
initialized. Comment lines are ignored. In the instruction, for the opcode the
OPTAB is searched to find the object code.
 If a symbol is there in the operand field, the symbol table is searched to get the
address value for this which gets added to the object code of the opcode. If the
address not found then zero value is stored as operands address. An error flag is
set indicating it as undefined. If symbol itself is not found then store 0 as
operand address and the object code instruction is assembled.
 If the opcode is BYTE or WORD, then the constant value is converted to its
equivalent object code( for example, for character EOF, its equivalent
hexadecimal value ‘454f46’ is stored). If the object code cannot fit into the
current text record, a new text record is created and the rest of the instructions
object code is listed. The text records are written to the object program. Once
the whole program is assemble and when the END directive is encountered, the
End record is written.

Machine-Dependent Assembler Features:


 Instruction formats and addressing modes
 Program relocation.

Instruction formats and Addressing Modes


 The instruction formats depend on the memory organization and the size of the
memory. In SIC machine the memory is byte addressable. Word size is 3 bytes.
So the size of the memory is 212 bytes.

DEPARMENT OF CSE, MCE Page 22


SS&CD [CS506] PART A - UNIT 1

 Accordingly it supports only one instruction format. It has only two registers:
register A and Index register.
 Therefore the addressing modes supported by this architecture are direct,
indirect, and indexed.
 Whereas the memory of a SIC/XE machine is 220 bytes (1 MB). This supports
four different types of instruction types, they are:
1 byte instruction
2 byte instruction
3 byte instruction
4 byte instruction
Instructions can be:
 – Instructions involving register to register
 – Instructions with one operand in memory, the other in Accumulator
 (Single operand instruction)
 – Extended instruction format
Addressing Modes:
 PC-relative or Base-relative addressing: op m
 Indirect addressing: op @m
 Immediate addressing: op #c
 Extended format: +op m
 Index addressing: op m,x
 register-to-register instructions
 larger memory -> multi-programming (program allocation)

Translations for the Instruction involving Register-Register addressing mode:


During pass 1 the registers can be entered as part of the symbol table itself. The value
for these registers is their equivalent numeric codes. During pass 2, these values are
assembled along with the mnemonics object code. If required a separate table can be
created with the register names and their equivalent numeric values.
Register name (A, X, L, B, S, T, F, PC, SW) and their values (0,1, 2, 3, 4, 5, 6, 8, 9)

Translation involving Register-Memory instructions:


In SIC/XE machine there are four instruction formats and five addressing modes.
Among the instruction formats, format -3 and format-4 instructions are Register-
Memory type of instruction. One of the operand is always in a register and the other
operand is in the memory. The addressing mode tells us the way in which the operand
from the memory is to be fetched.
There are two ways: Program-counter relative and Base-relative. This addressing
mode can be represented by either using format-3 type or format-4 type of instruction
format. In format-3, the instruction has the opcode followed by a 12-bit displacement
value in the address field. Where as in format-4 the instruction contains the mnemonic
code followed by a 20-bit displacement value in the address field.
Program-Counter Relative: In this usually format-3 instruction format is used. The
instruction contains the opcode followed by a 12-bit displacement value. The range of
displacement values are from 0 -2048. This displacement (should be small enough to
fit in a 12-bit field) value is added to the current contents of the program counter to get
the target address of the operand required by the instruction. This is relative way of
calculating the address of the operand relative to the program counter.
TA=PC+Disp

DEPARMENT OF CSE, MCE Page 23


SS&CD [CS506] PART A - UNIT 1

Hence the displacement of the operand is relative to the current program counter value.
The following example shows how the address is calculated:

Base-Relative Addressing Mode: in this mode the base register is used to mention the
displacement value. Therefore the target address is
TA = (base) + displacement value
This addressing mode is used when the range of displacement value is not sufficient.
Hence the operand is not relative to the instruction as in PC-relative addressing mode.
Whenever this mode is used it is indicated by using a directive BASE. The moment the
assembler encounters this directive the next instruction uses base-relative addressing
mode to calculate the target address of the operand.
When NOBASE directive is used then it indicates the base register is no more used to
calculate the target address of the operand. Assembler first chooses PC-relative, when
the displacement field is not enough it uses Base-relative.
LDB #LENGTH (instruction)
BASE LENGTH (directive)
:
NO BASE

DEPARMENT OF CSE, MCE Page 24


SS&CD [CS506] PART A - UNIT 1

In the above example the use of directive BASE indicates that Base-relative addressing
mode is to be used to calculate the target address. PC-relative is no longer used. The
value of the LENGTH is stored in the base register. If PC-relative is used then the
target address calculated is:
The LDB instruction loads the value of length in the base register which 0033. BASE
Directive explicitly tells the assembler that it has the value of LENGTH.
BUFFER is at location (0036)16
(B) = (0033)16
disp = 0036 – 0033 = (0003)16

20 000A LDA LENGTH 032026


::
175 1056 EXIT STX LENGTH 134000
Consider Line 175.
If we use PC-relative
Disp = TA – (PC) = 0033 –1059 = EFDA
PC relative is no longer applicable, so we try to use BASE relative addressing mode.
Immediate Addressing Mode:
In this mode no memory reference is involved. If immediate mode is used the target
address is the operand itself.

DEPARMENT OF CSE, MCE Page 25


SS&CD [CS506] PART A - UNIT 1

If the symbol is referred in the instruction as the immediate operand then it is


immediate with PC-relative mode as shown in the example below:

Indirect and PC-relative mode:


In this type of instruction the symbol used in the instruction is the address of the
location which contains the address of the operand. The address of this is found using
PC-relative addressing mode. For example:

The instruction jumps the control to the address location RETADR which in turn has
the address of the operand. If address of RETADR is 0030, the target address is then
0003 as calculated above.

Program Relocation:
 The actual starting address of the program is not known until load time
 An object program that contains the information necessary to perform this kind
of modification is called a relocatable program
 No modification is needed: operand is using program-counter relative or base
relative addressing
 The only parts of the program that require modification at load time are those
that specified direct (as opposed to relative) addresses
Absolute program, starting address 1000
e.g. 55 101B LDA THREE 00102D
Relocate the program to 2000
e.g. 55 101B LDA THREE 00202D
Each Absolute address should be modified
 Except for absolute address, the rest of the instructions need not be modified
not a memory address (immediate addressing), PC-relative, Base-relative.
 The only parts of the program that require modification at load time are those
that specify direct addresses.

DEPARMENT OF CSE, MCE Page 26


SS&CD [CS506] PART A - UNIT 1

 The above diagram shows the concept of relocation. Initially the program is
loaded at location 0000. The instruction JSUB is loaded at location 0006. The
address field of this instruction contains 01036, which is the address of the
instruction labeled RDREC.
 The second figure shows that if the program is to be loaded at new location
5000. The address of the instruction JSUB gets modified to new location 6036.
 Likewise the third figure shows that if the program is relocated at location
7420, the JSUB instruction would need to be changed to 4B108456 that
correspond to the new address of RDREC.
 The only part of the program that require modification at load time are those
that specify direct addresses. The rest of the instructions need not be modified.
 The instructions which doesn’t require modification are the ones that is not a
memory address (immediate addressing) and PC-relative, Base-relative
instructions.
 From the object
 program, it is not possible to distinguish the address and constant The
assembler must keep some information to tell the loader. The object program
that contains the modification record is called a relocatable program.
 For an address label, its address is assigned relative to the start of the program
(START 0). The assembler produces a Modification record to store the starting
location and the length of the address field to be modified. The command for
the loader must also be a part of the object program. The Modification has the
following format:
Modification record
Col. 1 M
Col. 2-7 Starting location of the address field to be modified, relative to the
beginning of the program (Hex)
Col. 8-9 Length of the address field to be modified, in half-bytes (Hex)
One modification record is created for each address to be modified The length is stored
in half-bytes (4 bits) The starting location is the location of the byte containing the
leftmost bits of the address field to be modified. If the field contains an odd number of
half-bytes, the starting location begins in the middle of the first byte.

DEPARMENT OF CSE, MCE Page 27


SS&CD [CS506] PART A - UNIT 1

In the above object code the red boxes indicate the addresses that need modifications.
The object code lines at the end are the descriptions of the modification records for
those instructions which need change if relocation occurs. M00000705 is the
modification suggested for the statement at location 0007 and requires modification 5-
half bytes. Similarly the remaining instructions indicate.

DEPARMENT OF CSE, MCE Page 28

You might also like