KEMBAR78
Module 2 Assemblers | PDF | Assembly Language | Input/Output
0% found this document useful (0 votes)
19 views101 pages

Module 2 Assemblers

The document outlines the syllabus and key concepts of the CSC 602 course on System Programming and Compiler Construction, focusing on assemblers, assembly language programming, and the IBM 360 architecture. It discusses the structure and types of assembly language statements, the assembler's design, and the assembler process, including handling forward references. Additionally, it provides examples of assembly programs and pseudo-operations used in assembly language.

Uploaded by

hajimastanbaap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views101 pages

Module 2 Assemblers

The document outlines the syllabus and key concepts of the CSC 602 course on System Programming and Compiler Construction, focusing on assemblers, assembly language programming, and the IBM 360 architecture. It discusses the structure and types of assembly language statements, the assembler's design, and the assembler process, including handling forward references. Additionally, it provides examples of assembly programs and pseudo-operations used in assembly language.

Uploaded by

hajimastanbaap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 101

System Programming and Compiler

Construction
CSC 602

Subject Incharge
Varsha Shrivastava
Assistant Professor
email: varshashrivastava@sfit.ac.in
Room No: 407

1
CSC 602 System Programming and
Compiler Construction
Module 2
Assembler

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 2
Content as per syllabus

 Introduction
 Elements of Assembly Language programming,
Assembly scheme
 Pass structure of assembler
 Assembler Design:
 Two pass assembler Design and
 Single pass Assembler Design for Hypothetical / X86
family processor
 Data structures used

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 3
Introduction
• Assembler is system software which converts an assembly
language
• The input to the assembler is a source code written in assembly
language (using mnemonics) and the output is an object code.

• Basic Assembler functions:


• Translating mnemonic language to its equivalent object code.

• Assigning machine addresses to symbolic labels.

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 4
Elements of Assembly Language programming

Assembler languages-structure
<Label> <Mnemomic> <Operands> Comments
• Label
• symbolic labeling of an assembler address (command
address at Machine level)
• Mnemomic
• Symbolic description of an operation
• Operands
• Contains of variables or address if necessary
• Comments
• ignored by assembler
• used by humans to document/understand programs

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 5
Elements of Assembly Language programming

Types of Assembly Language Statements


ASSEMBLY
LANGUAGE
STATEMENTS

ASSEMBLER
IMPERATIVE DECLARATIVE
DIRECTIVE
STATEMENTS STATEMENT
STATEMENTS

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 6
Elements of Assembly Language programming

Types of Assembly Language Statements


Imperative statements
An imperative statement in assembly
language indicates the action to be
performed during execution of
assembly statement
Ex:- A 1,FOUR

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 7
Elements of Assembly Language programming

Types of Assembly Language Statements


Assembler Directives
• These statements instructs the
assembler to perform certain action
during the assembly of a program.
• Ex START 100
USING *, 15
USING indicates to the assembler which general
register to use as a base and what its content will be.
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 8
Elements of Assembly Language programming

Types of Assembly Language Statements


Declarative Statement
• These statements declares the storage area or
declares the constant in program.
• EX: A DS 1
ONE DC “1”
[Label] DS <constant>
The DS statement reserves areas of memory and
associates names with them.
[Label] DC ‘<value>’
The DC statement constructs memory words
containing constants.
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 9
Terms to remember

• A pseudo-op is an assembly language


instruction that specifies an operation of the
assembler i.e
about the base register & its contents e.g.
USING, DC, DS instruction.
• On the other hand, a machine-op
instruction. That represents a machine
instruction to the assembler e.g. BR
instruction is a machine-op instruction

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 10
General Machine Architecture
IBM 360 Architecture

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 11
General Machine Architecture
IBM 360 Architecture

Instruction
interpreter

Instruction Interpreter H/W is a group of circuits


that perform the operation specified by the
instruction fetched from the memory
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 12
General Machine Architecture
IBM 360 Architecture

Location Counter

Location Counter is also called as Program/ Instruction


Counter, it points to the current instruction being executed.
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 13
General Machine Architecture
IBM 360 Architecture

Working
Registers

The working registers are often called as the "scratch pads"


because they are used to store temporary values while
calculation is in progress.
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 14
General Machine Architecture
IBM 360 Architecture

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 15
General Machine Architecture
IBM 360 Architecture

MAR and
MBR

This CPU interfaces with Memory through


MAR & MBR
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 16
General Machine Architecture
IBM 360 Architecture

MAR and
MBR

MAR (Memory Address Register) - contains address of memory location (to


be read from or stored into)
MBR (Memory Buffer Register) - contains copy of address specified by MAR
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 17
General Machine Architecture
IBM 360 Architecture
Memory
Controller

Memory controller is used to transfer data between


MBR & the memory location specified by MAR
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 18
General Machine Architecture
IBM 360 Architecture
I/O
Channel

The role of I/O Channels is to input or output


information from memory.
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 19
IBM 360/370 Structure
• Memory
• 224 bytes (16 million bytes)
• 3 components
• Offset
• Base Register
• Index Register
• Example: add instruction
A 1, 901(2,15)
instructio Base
n register
Register to which Index
number has to be added Offset register

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 20
IBM 360/370 Structure
• Registers
• 16 general purpose registers of 32 bits each
• Can be used for various arithmetic and logical
operations as base registers
• Can be used as temporary storage for
operations
• In base register form, they aid in formation of
address
• 4 floating point registers of 64 bits each
• 64 bit Program Status Word (Flags)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 21
IBM 360/370 Structure

• Data
• B’ 0000 0001 0010 1100

• X’ 0 1 2 C

• Prefix
• X – Hexadecimal
• B – Binary

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 22
IBM 360/370 Structure
Instructions
Register Operands
• RR format 1 2

OPCODE R1 R2
0 7 8 11 12 15

• RX format
Register Storage
Operand 1 Operand 2

OPCODE R1 X2 B2 D2
0 7 8 11 12 15 16 19 20 31

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 23
IBM 360/370 Structure

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 24
IBM 360/370 Structure

• Special Features
• Has hardware protection in blocks of 2048 bytes
• Has elaborate interrupt structure

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 25
Pseudo Operation Code (Pseudo-op)
“Pseudo Op can also be termed as Assembler
Directives”
START : START is a pseudo-op that tell the
assembler where the beginning of the program is
and allows the user to give a name to the
program.
Eg: TEST START
END : END is a pseudo-op tell the assembler that
the end of the program has been reached
Eg: END
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 26
Pseudo Operation Code (Pseudo-op)
USING : USING is a pseudo-op that indicates to
the assembler which general purpose register to
use as a base register and what its content will be.
Eg: USING *,15
USING BEGIN+2,15
DROP : DROP is a pseudo-op tell which indicates
unavailable base register.
Eg: DROP 15

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 27
Pseudo Operation Code (Pseudo-op)
DS : DS is a pseudo-op which make the assembler
reserve a space in memory. DS is only for define
storage.
Eg: BLOCK DS 5F

DC : DC is used to define storage and store a


constant.
Eg: FOUR DC 1F ‘4’

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 28
Pseudo Operation Code (Pseudo-op)
LTORG : LTORG is a pseudo-op which tells the
assembler to place the encountered literals at an
earlier locations.
Eg: BLOCK DS 5F

EQU : EQU is pseudo-op allow the programmer to


define variables.
Eg: BASE EQU 15

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 29
Machine Operation Code (Machine-op)
BALR : Branch and link- load the register with next
address and branch to the address in the second
field. (RR format instruction)
Eg: BALR 15,0

BR : Unconditionally Branch to the location whose


address in register.
Eg: BR 14

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 30
Machine Operation Code (Machine-op)
BCT : Branch on Count- RX Instruction
This command decrements the given register by
one and if the result is positive, branches to the
address in the second field
Eg: BCT 3, LOOP

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 31
Assembly language program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 32
Types of Assembler

• Single pass Assembler

• Multi pass Assembler

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 33
Assembler Process

ASSEMBLY
LANGUAGE PASS1 PASS2 EXECUTABLE
PROGRAM IMAGE

SYMBOL
TABLE

First Pass:
scan program file
find all labels and calculate the corresponding addresses;
this is called the symbol table
Second Pass:
convert instructions to machine language,
using information from symbol table
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 34
Problem of Forward Reference

• Variables whose declaration is later in the


code is encountered, the forward reference
problem occurs.

• To avoid the forward reference problem:


i) Declare the symbols before using it
ii) Use multi pass assemblers

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 35
Example : Assembly Program

JOHN START 0
USING *, 15
L 1, FIVE
A 1,FOUR
ST 1, TEMP
FOUR DC F’4’
FIVE DC F’5’
TEMP DS 1F
END

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 36
Problem of Forward Reference

JOHN START 0
USING *, 15
L 1, FIVE
A 1,FOUR
ST 1, TEMP
FOUR DC F’4’
FIVE DC F’5’
TEMP DS 1F
END

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 37
Assembler
SOURCE PROGRAM FIRST PASS SECOND PASS
JOHN START 0
USING *, 15
L 1, FIVE
A 1,FOUR
ST 1, TEMP
FOUR DC F’4’
FIVE DC F’5’
TEMP DS 1F
END

Register 15,base register and at execution time will contain


the address of the first instruction of the program
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 38
Assembler
SOURCE PROGRAM FIRST PASS SECOND PASS
JOHN START 0
USING *, 15
L 1, FIVE 0 L 1,_(0,15)
A 1,FOUR 4 A 1,_(0,15)
ST 1, TEMP 8 ST 1,_(0,15)
FOUR DC F’4’ 12 4
FIVE DC F’5’ 16 5
TEMP DS 1F 20 --
END

Register 15,base register and at execution time will contain


the address of the first instruction of the program
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 39
Assembler
SOURCE PROGRAM FIRST PASS SECOND PASS
JOHN START 0
USING *, 15
L 1, FIVE 0 L 1,_(0,15) 0 L 1, 16(0,15)
A 1,FOUR 4 A 1,_(0,15) 4 A 1, 12(0,15)
ST 1, TEMP 8 ST 1,_(0,15) 8 ST 1, 20(0,15)
FOUR DC F’4’ 12 4 12 4
FIVE DC F’5’ 16 5 16 5
TEMP DS 1F 20 -- 20 --
END

Register 15,base register and at execution time will contain


the address of the first instruction of the program
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 40
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 41
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 42
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 43
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 44
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 45
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 46
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 47
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 48
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 49
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 50
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 51
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 52
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 53
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 54
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 55
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 56
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 57
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 58
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 59
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 60
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 61
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 62
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 63
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 64
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 65
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 66
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 67
Example : Assembly Program

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 68
Intermediate Generated Code

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction
Department of Computer Engineering Ms. Varsha Shrivastava 69
Points to remember :-

• For all symbols and literals used in RX Format, Base


index addressing is used.
• It is of the form – offset (index, base)
• To calculate offset, value of current base register is
subtracted from symbol/literal value, index register
value is specified in instruction inside brackets (if
not specified then value is 0)
• Base register that is chosen is register with value
closest to symbol/literal value.

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 70
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Example

• Till statement 10, value of base register 15 is 0


• After statement 10, value of base register 15 is 6
• After statement 12, value of base register 13 is 8064

Statement 11 – L DATABASE,=A(DATA1)

Symbol/ Value Base Register Value Offset Final Value


Literal (with index)
A(DATA1) 48 15 6 48 – 6 = 42 42(0,15)

Statement 11 – L 13, 42(0,15)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 71
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Example

Statement 14 – LOOP L AC,DATA1(INDEX)

Symbol/ Value Base Register Value Offset Final Value


Literal (with index)
A(DATA1) 48 15 6 48 – 6 = 42 42(0,15)
DATA1 8064 13 8064 8064 – 8064 = 0 0(3,13)
Statement 14 – LOOP L 2, 0(3,13)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 72
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Example

Statement 16 – A AC,=F’5’

Symbol/ Value Base Register Value Offset Final Value


Literal (with index)
A(DATA1) 48 15 6 48 – 6 = 42 42(0,15)
DATA1 8064 13 8064 8064 – 8064 = 0 0(3,13)
F’5 52 15 6 52 – 6 = 46 46(0,15)

Statement 16 – A 2, 46(0,15)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 73
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Example

Statement 17 – ST AC,SAVE(INDEX)

Symbol/ Value Base Register Value Offset Final Value


Literal (with index)
A(DATA1) 48 15 6 48 – 6 = 42 42(0,15)
DATA1 8064 13 8064 8064 – 8064 = 0 0(3,13)
F’5 52 15 6 52 – 6 = 46 46(0,15)
SAVE 64 15 6 64 – 6 = 58 58(3,15)

Statement 17 – ST 2, 58(3,15)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 74
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Example

Statement 18 – A INDEX, =F’4’

Symbol/ Value Base Register Value Offset Final Value


Literal (with index)
A(DATA1) 48 15 6 48 – 6 = 42 42(0,15)
DATA1 8064 13 8064 8064 – 8064 = 0 0(3,13)
F’5 52 15 6 52 – 6 = 46 46(0,15)
SAVE 64 15 6 64 – 6 = 58 58(3,15)
F’4 56 15 6 56 – 6 = 50 50(0,15)

Statement 18 – A 3, 50(0,15)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 75
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Example

Statement 19 – C INDEX, =F’8000’

Symbol/ Value Base Register Value Offset Final Value


Literal (with index)
A(DATA1) 48 15 6 48 – 6 = 42 42(0,15)
DATA1 8064 13 8064 8064 – 8064 = 0 0(3,13)
F’5 52 15 6 52 – 6 = 46 46(0,15)
SAVE 64 15 6 64 – 6 = 58 58(3,15)
F’4 56 15 6 56 – 6 = 50 50(0,15)
F’8000 60 15 6 60 – 6 = 54 54(0,15)

Statement 19 – C 3, 54(0,15)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 76
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Example

Statement 20 – BNE LOOP

Symbol/ Value Base Register Value Offset Final Value


Literal (with index)
A(DATA1) 48 15 6 48 – 6 = 42 42(0,15)
DATA1 8064 13 8064 8064 – 8064 = 0 0(3,13)
F’5 52 15 6 52 – 6 = 46 46(0,15)
SAVE 64 15 6 64 – 6 = 58 58(3,15)
F’4 56 15 6 56 – 6 = 50 50(0,15)
F’8000 60 15 6 60 – 6 = 54 54(0,15)
LOOP 12 15 6 12 – 6 = 6 6(0,15)

Statement 20 – BC 7, 6(0,15)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 77
Department of Computer Engineering Ms. Varsha Shrivastava
Final Generated Code

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 78
Department of Computer Engineering Ms. Varsha Shrivastava
Practice :-Compute Pass 1 & Pass 2

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 79
Department of Computer Engineering Ms. Varsha Shrivastava
Solution :-

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 80
Department of Computer Engineering Ms. Varsha Shrivastava
Practice :-
For the following assembly language program Construct ST, LT, BT
and formulate the corresponding object code using these tables

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 81
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
1. Specify the problem
2. Specify data structures
3. Define format of data structures
4. Specify algorithm
5. Look for modularity [capability of one
program to be subdivided into
independent programming units.]
6. Repeat 1 through 5 on modules.
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 82
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
1. Specify the problem :
Pass1: Define symbols & literals.
1) Determine length of m/c instruction [MOTGET1]
2) Keep track of Location Counter [LC]
3) Remember values of symbols until pass2 [STSTO]
4) Process some pseudo ops, eg. EQU, DS etc [POTGET1]
5) Remember Literals [LITSTO]

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 83
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
1. Specify the problem :
Pass2: Generate object program
1) Look up value of symbols [STGET]
2) Generate instruction [MOTGET2]
3) Generate data (for DS, DC & literals)
4) Process pseudo ops [POTGET2]

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 84
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
2. Specify Data Structure:
Pass1: Databases
• Input source program
• “LC” location counter is used to keep track of each instruction’s
address.
• Machine operation table (MOT) [Symbolic mnemonic & length]
• Pseudo operation table [POT], [pseudo mnemonic & action]
• Symbol Table (ST) stores each table & it’s value.
• Literal Table (LT), to store each literal (variable) & it’s location.
• Copy of input to used later by PASS-2.
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 85
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
2. Specify Data Structure:
Pass2: Databases
• Copy of source program input to Pass1.
• Location Counter (LC)
• MOT [Mnemonic, length, binary m/c op code, etc.]
• POT [Mnemonic & action to be taken in Pass2
• ST [prepared by Pass1, label & value]
• Base Table [or register table] indicates which registers are
currently specified using ‘USING’ pseudo op & what are
contents.
• Literal table prepared by Pass1. [Lit name & value].
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 86
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
Use of Databases by Assembler Passes

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 87
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
3. Format of Data Structure:
• Machine Operation Table
• The op-code is the key and it’s value is the binary op
code equivalent, which is used for use in generating
machine code.
• The instruction length is stored for updating the location
counter.
• Instruction format is use in forming the m/c language
equivalent

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 88
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
3. Format of Data Structure:
• Machine Operation Table (MOT)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 89
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
3. Format of Data Structure:
• Pseudo Operation Table (POT)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 90
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
3. Format of Data Structure:
• Symbol Table (ST) and Literal Table (LT)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 91
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
3. Format of Data Structure:
• Base Table (BT)

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 92
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
What goes where?
• ST (Symbol Table) – Labels & their values
• LT (Literal Table) – Data (F’10’, F’49’, F’4’…)
• MOT (Machine Op Table) – Machine opcodes, i.e.,
instructions along with their length (2/4/6 bytes) in
Pass1.
• In Pass2, we store the name, length, binary code and
format (RR, RX, SS…).
• POT (Pseudo Op Table) – Pseudo opcodes or action to be
taken in Pass1 and Pass2
• BT (Base Table) – the registers used for base addresses
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 93
Department of Computer Engineering Ms. Varsha Shrivastava
Problems with single pass assembly?

• Forward Reference
• 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
• When the definition for the symbol is encountered,
scans the reference list and inserts the address.
• At the end of the program, reports the error if there are
still SYMTAB entries indicated undefined symbols.

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 94
Department of Computer Engineering Ms. Varsha Shrivastava
Pass 1-
Assembler
Flow chart

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 95
Department of Computer Engineering Ms. Varsha Shrivastava
Pass 2-
Assembler
Flow chart

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 96
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler Design
General Design Procedure of Assembler
5. Look for Modularity :-

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 97
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 98
Department of Computer Engineering Ms. Varsha Shrivastava
Assembler

St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 99
Department of Computer Engineering Ms. Varsha Shrivastava
University Questions
 State the reason for the assembler to be a multi pass
program
 What is forward reference problem? How is it handled in
two pass assembler? Explain with the help of flowchart the
working of a two pass assembler.
 Explain the databases used by each pass of the 2-pass
assembler in detail.
 With reference to assembler explain the following tables
with suitable examples:
(a) POT (b) MOT (c) ST (d) LT
 Explain the working of single pass assembler. Show the
structure of the database used
 Practice Assembler programs
St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 10
Department of Computer Engineering Ms. Varsha Shrivastava 0
THE END!

Have a nice day!


St. Francis Institute of Technology 08 Feb 2021 CSC 602:System Programming & Compiler Construction 10
Department of Computer Engineering Ms. Varsha Shrivastava 1

You might also like