Assembly Lang Details Unit1
Assembly Lang Details Unit1
Assembly Language
Subject Introduction to System Programming
• Imperative Statements:
• Declarative/Declaration Statements:
• Assembler Directive:
Subject Introduction to System Programming
Imperative Statements
• Imperative means mnemonics
• These are executable statements.
• Each imperative statement indicates an action to
be taken during execution of the program.
• E.g MOVER
. BREG, X
STOP
READ X
ADD AREG, Z
Subject Introduction to System Programming
Declarative Statements
• Declaration statements are for reserving
memory for variables.
• We can specify the initial value of a variable.
• It has two types:
• DS // Declare Storage
• DC // Declare Constant
Subject Introduction to System Programming
DS(Declare Storage):
• Syntax:
• [Label] DS <Constant specifying size>
• E.g. X DS 1
DC (Declare Constant):
Syntax:
[Label ] DC <constant specifying value>
E.g Y DC ‘5’
Subject Introduction to System Programming
Assembler Directive
• Assembler directive instruct the assembler to
perform certain actions during assembly of a
program.
• Some assembler directive are:
START <address constant>
END
Subject Introduction to System Programming
8
Subject Introduction to System Programming
1 AD
2 IS
3 IS
4 IS
5 IS
6 DS
7 DS
8 AD
Subject Introduction to System Programming
• ORIGIN
• EQU
• LTORG
Subject Introduction to System Programming
Definitions
• LC:
• Symbol:
• Literals:
• Procedures:
Subject Introduction to System Programming
How LC Operates?
Sr. NO LC
1 START 100
2 MOVER AREG, X
3 MOVER BREG, Y
5 MOVEM AREG, X
6 X DC ‘10’
7 Y DC ‘15’
8 END
Subject Introduction to System Programming
How LC Operates?
Sr. NO LC
1 START 100
6 X DC ‘10’ 104
7 Y DC ‘15’ 105
8 END
Subject Introduction to System Programming
1
2
3
4
5
6
7
8
9
10
Subject Introduction to System Programming
Machine Structure
Subject Introduction to System Programming
Machine Structure
Subject Introduction to System Programming
• STOP
• ADD
• SUB
• MULT
• MOVER
• MOVEM
• First operand is always a CPU register. • COMP
• Second operand is always memory operand. • BC
• READ and PRINT instructions do not use first operand. • DIV
• READ
• The STOP instruction has no operand. • PRINT
Subject Introduction to System Programming
START 01
END 02
LTORG 03
ORIGIN 04
EQU 05
Subject Introduction to System Programming
02 DC 02
Subject Introduction to System Programming
2 BREG 02
3 CREG 03
Subject Introduction to System Programming
ASSEMBLER
• An assembly language program can be translated into
machine language.
It involves following steps:
1. Find addresses of variable.
2. Replace symbolic addresses by numeric
addresses.
3. Replace symbolic opcodes by machine
operation codes.
4. Reserve storage for data.
Subject Introduction to System Programming
Step 1
• We can find out addresses of variable using LC.
• First identify all variables in your program.
• START 100
• MOVER AREG, X
• MOVER BREG, Y
• ADD AREG, X
• MOVEM AREG, X
• X DC ‘10’
• Y DC ‘15’
• END
Subject Introduction to System Programming
Step 1
Sr. NO LC
1 START 100
6 X DC ‘10’ 104
7 Y DC ‘15’ 105
8 END
Subject Introduction to System Programming
1 X 104
2 Y 105
Subject Introduction to System Programming
• START 100
• MOVER AREG, 104
• MOVER BREG, 105
• ADD AREG, 104
• MOVEM AREG, 104
• X DC ‘10’ Memory is reserved but no
• Y DC ‘15’ code is generated.
• END
Subject Introduction to System Programming
105
106
107
Subject Introduction to System Programming
Question For U
START 102
READ X
READ Y
MOVER AREG, X
ADD AREG, Y
MOVEM AREG, RESULT
PRINT RESULT
STOP
X DS 1
Y DS 1
RESULT DS 1
END
Subject Introduction to System Programming
Question For u
START 101
READ N
MOVER BREG, ONE
MOVEM BREG, TERM
AGAIN MULT BREG, TERM
MOVER CREG, TERM
ADD CREG, ONE
MOVEM CREG, TERM
COMP CREG, N
BC LE, AGAIN
MOVEM BREG, RESULT
PRINT RESULT
STOP N
DS 1
RESULT DS 1
ONE DC ‘1’
TERM DS 1
Subject Introduction to System Programming
Apply LC
Backpatching
Step 1: Construct TII(Table of incomplete instruction)
Step 2 :The operand field of instruction containing a forward reference is left blank initially.
Subject Introduction to System Programming
• Step 3: After encountering END statement symbol table would contain the address of all
symbols defined in the source program.
X 104
ONE 105
TEN 106
Subject Introduction to System Programming
Assembler
• An Assembler is a translator which translates assembly
language code into machine language with help of data
structure.
• Statement of Problem
• Data Structure
• Format of databases
• Algorithms
• Look for modularity.
Subject Introduction to System Programming
Statement of Problem
• We want to convert assembly language program into
machine language.
Subject Introduction to System Programming
Format of Databases
• Symbol Table:
Name of Symbol address
• Literal Table:
Literal address
MOT:
Mnemonic Machine Opcode Class Length
Apply LC
Construct Symbol table
0 X 214
1 L1 202
2 NEXT 207
3 BACK 202
INTERMEDIATE CODE
Format for intermediate code:
• For every line of assembly statement
• one line of intermediate code is generated.
• Each mnemonic field is represented as
• (statement class, and machine code)
Source Program
Subject Introduction to System Programming
Subject Introduction to System Programming
Subject Introduction to System Programming
Subject Introduction to System Programming
Subject Introduction to System Programming
Subject Introduction to System Programming
Output of Pass 1
Intermediate Code
Symbol Table
Literal Table
Subject Introduction to System Programming
Intermediate Code
Symbol Table
Literal Table
Subject Introduction to System Programming
Pass 2
Imp Notes :
1. For Assembler directive we don’t
write opcode.
2. Among Declarative Statements,
we write machine code only for
Declarative Constant(DC), we write
constant number.
Subject Introduction to System Programming