ASSEMBLER
ASSEMBLER
FUNCTION OF AN ASSEMBLER
ASSEMBLY
LANG.
PROGRAM
DATABASE
ASSEMBLER
MACHINE LANG. &
OTHER
INFORMATION
FOR LOADER
2
8/3/2016jaya
ASSEMBLER
 General format for assembly language statement
Example:
JOHN START 0
FOUR DC F’4’
A 2,FOUR
Opcode ------- 1 digit
Register operand ---------- 1 digit
Memory operand ---------- 3 digits
[Label *] [opcode] [operand1]*, [operand2]*
3
8/3/2016jaya
ASSEMBLER
 LABEL FIELD
when processed by assembler it will store this
label and its information.
Example:
JHON
DATA
4
8/3/2016jaya
ASSEMBLER
 Mnemonic Opcode Field
instructions
 Types of assembly statements
Imperative statements
Declarative statements
Directive statements
5
8/3/2016jaya
ASSEMBLER
 Imperative statements
Specifies the operation to be performed during
the execution of program
Example:
MOVEM AREG , B
MOVER AREG , C
ADD AREG , ONE
COMP AREG , =‘1’
SUB BREG , =‘2’
constant
memory
register
6
8/3/2016jaya
ASSEMBLER
 Declarative Statements
declare constant or storage variable
 Types of declarative statements:-
 DS(Declare Storage)
ex: AB DS 1
X DS 200
 DC(Declare Constant)
ex: ONE DC 1
name
1 word
mem.
7
8/3/2016jaya
ASSEMBLER
 Assembler Directive statements or pseudo
ops
It specifies the operation to be performed
during the process of assembly .
 Types of pseudo opcodes
 START
 END
 LTORG
 ORIGIN
 EQU
8
8/3/2016jaya
ASSEMBLER
 START
 Tells the start of program
 Gives name to program
 Sets LC
 ex:
TEST START
JHON START 484
9
8/3/2016jaya
ASSEMBLER
 END
 Tells end of program.
 Ex: END
 LTORG
 Tells the assembler to place the literals at an earlier
location
 Used in very long programs
 Ex: LTORG
10
8/3/2016jaya
ASSEMBLER
 ORIGIN
used to reset location counter
default value of reset is LC=0
Ex:
ORIGIN <address space>
11
8/3/2016jaya
ASSEMBLER
 EQU
allows to define variable
Syntax: <symbol> EQU <address space>
Ex: BASE EQU 15
12
8/3/2016jaya
ASSEMBLER
 Operand Field
with this assembler perform actions
 Types of operands
Register
Symbol
Literal
13
8/3/2016jaya
ASSEMBLER
 Advantages of assembler
 Unambiguous code and compact
 As close to machine as possible
 Extremely fast
 Compiled assembly programs are small
 Storage can be allocated and deallocated dynamically.
14
8/3/2016jaya
ASSEMBLER
 Advantages of assembly Language
 Easy to memorize
 Mnemonic opcodes are helpful for diagnostics
 Program modification is easy
 Manual conversion of constants into machine
representation
15
8/3/2016jaya
ASSEMBLER
 General Design Procedure
 Specify the problem
 Specify data structure
 Define format of data structure
 Specify algorithm
 Look for modularity
 Repeat 1 through 5 on modules
16
8/3/2016jaya
ASSEMBLER
 Statement of problem
 Processing of each assembly instruction varies depending upon types of
instruction.
 Processing of each assembly instruction assembler processes each field of
instruction.
 In this labels or symbols can appear before they are defined, so it is
convenient to make two passes over the input.
 Passes of assembler
 Pass 1
 Pass2
 Generate instructions (basic requirement)
 Evaluate the mnemonic in the operation field to produce its
machine code
 Evaluate the subfields-find the value of each symbol, process
literals and assign addresses.
 Process pseudo ops
17
8/3/2016jaya
ASSEMBLER
 Pass1: purpose - define symbol and literals
 Determine length of machine instructions(MOTGET1)
 Keep track of Location Counter(LC)
 Remember values of symbols until pass 2(STSTO)
 Process some pseudo ops , e.g. EQU, DS (POTGET1)
 Remember literals(LITSTO)
 Pass2: purpose - generate object program
 Look up value of symbols(STGET)
 Generate instructions(MOTGET2)
 Generate data(for DS, DC, and literals)
 Process pseudo ops(POTGET2)
18
8/3/2016jaya
ASSEMBLER
 DATA STRUCTURES
second step of design procedure for assembler
 Pass 1 data base:
 Input source program
 A Location Counter(LC),
 The Machine Opcode Table(MOT)
 The Pseudo Opcode Table(POT)
 The Symbol Table(ST)
 The Literal Table(LT)
 A copy of input used b pass2
19
8/3/2016jaya
ASSEMBLER
 DATA STRUCTURES
second step of design procedure for assembler
 Pass 2 data base:
 Copy of source program input to pass 1
 A Location Counter(LC),
 The Machine Opcode Table(MOT)(mnemonic, length, binary m/c opcode and
format)
 The Pseudo Opcode Table(POT)
 The Symbol Table(ST)
 The Base Table(BT)
 A workspace , INST
 A workspace, PRINT LINE
 A workspace PUNCH CARD
 Output deck of assembled instruction
20
8/3/2016jaya
ASSEMBLER
 MOT(Machine Op-code Table)
21
Mnemoni
c opcode
(4 bytes)
(char)
Binary opcode
(1 byte)
(hexadecimal)
Instruction
Length
(2 bits)
(binary)
Instruction
Format
(3 bit)
(binary)
Not used in
this design
(3 bits)
“Abbb” 5A 10 001
“AHbb” 4A 10 001
“ALbb” 5E 10 001
“ALRb” 1E 01 000
“ARbb” 1A 01 000
-------------- ------------ -------------- --------------
“MVCb” D2 11 100
000 RR
001 RX
010 RS
011 SI
100 SS
Instruction format
01 1 half words 2 bytes
10 2 half words 4 bytes
11 3 half words 6 bytes
Instruction
length
6 bytes
8/3/2016jaya
ASSEMBLER
 MOT example
22
NAME MNEMONIC BINARY
OPCODE
FORMA
T
OPERANDS
Add(c) AR 1A RR R1,R2
Add (c ) A 5A RX R1,D2(X2,B2)
Branch &
link
BALR 05 RR R1,R2
Start I/O SIO 9C SI D1(B1)
Move MVC D2 SS D1(L,B1),D2(B2)
8/3/2016jaya
ASSEMBLER
 POT (pseudo opcode table)
23
PSEUDO
OPCODE
(5 BYTES CHAR)
ADDRESS OF ROUTINES TO
PROCESS PSEUDO OP
(3 BYTES=24 BIT ADDRESS
”DROPb” P1 DROP
“ENDbb” P1 END
“EQUbb” P1 EQU
“START” P1 START
“ORIGIN” P1 USING
8/3/2016jaya
ASSEMBLER
 ST(symbol table) 14 bytes per entry
24
SYMBOL
(8 BYTES
CHAR)
VALUE
(4 BYTE)
HEXADECIMAL
LENGTH
(1 BYTE)
HEXADECIMAL
RELOCAT
ION
(1 BYTE)
CHAR
“SSSSbbbb” 0000 01 “R”
“FOURbbbb” 0000 04 “R”
“FIVEbbbb” 0010 04 “R”
“TEMPbbbb” 0014 04 “R”
14 bytes per
entry
8/3/2016jaya
ASSEMBLER
 LT(Literal table) 14 bytes per entry
25
LITERAL
(8 BYTES CHAR)
VALUE
(4 BYTE)
HEXADECIMAL
LENGTH
(1 BYTE)
HEXADECIMAL
RELOCAT
ION
(1 BYTE)
CHAR
A(DATA1) 0048 04 “R”
F’800’ 0060 04 “R”
8/3/2016jaya
ASSEMBLER
 BT(Base Table) 15 entries
26
AVAILABILITY
INDICATOR
(1 BYTE)
CHAR
DESIGNED RELATIVE ADDRESS
CONTENTS OF BASE REGISTER
(3 BYTES = 24 BIT ADDRESS)
HEXADECIMAL
“N” ------------------
“N” -----------------
----------------------- -----------------
“N” ----------
“Y” 00 00 00
N =register specified
in USING
Y= never specified
8/3/2016jaya
Pass 1
LC  0
Read card from file copy
READ1
Assign value to
symbol in label field
STSTO
L  length
Process any literals, enter into
literal table
LTSTO
Write copy of card on file for use
by pass2
WRITE1
Search pseudo-op table
POTGET1
Which one
?
Adjust LC to proper
alignment
L  length of data
field
DLENGTH
Assign current value of LC
to symbol
STSTO
Evaluate operand
field
EVAL
Search machine-op table
MOTGET1
Assign storage
locations to
literals
LITASS
Rewind and reset
copy file
On to pass 2
found
DS
DC
NO
EQU
USING
,
DROP END
Not found
YES
LC  LC + L
Is there
symbol in
label field
8/3/2016jaya
Pass 2
LC  0
Read card from file copy
READ2
Enter base reg. no.
and value into base
table
BTSTO
Get op-code byte and format
code
L  length
Type of instruction
Evaluate both register
expressions and insert into 2nd
byte
EVAL
“punch”
Assembled instruction
PUNCH
“print” assembly listing line
PRINT
LC  LC + L
Search pseudo-op table
POTGET2
Which one
?
Adjust LC to proper
alignment
L  length of data field
DLENGTH
DC
or
DS
Evaluate register and index
expressions and insert into 2nd
byte
EVAL
Calculate effective
address(EA) of operand
EVAL
Determine appropriate
displacement and base register D
+C(B) =CA
BTGET
Put B & D into bytes 3 and 4
From constant and
insert in assembled
program
DCGEN
Evaluate operand
EVALSearch pseudo-op table
MOTGET2
Print listing
PRINT
Indicate base
reg. no.
unavailable
BTDROP
Generate literals
for entries in literal
table
LTGEN
STOP
a
b
a
b
found
DS
DC
DC
DS
EQU
STAR
T
USING
DROP END
Not found
RX
RR
8/3/2016jaya
ASSEMBLER
 Look for modularity
 PASS1
29
FUNCTIO
N
DESCRIPTION
READ1 Read the next assembly source card.
POTGET1 Search the pass 1 pseudo-op table(POT) for a match with the
operation field of the current source card.
MOTGET1 Search the machine –op table (MOT) for a match with the operation of
the current source card.
STSTO Store a label and its associated value into the symbol table (ST)
LTSTO Store a literal into the literal table(LT)
WRITE1 Write a copy of the assembly source card on a storage device for use
by pass 2
DLENGTH Scan operand field of DS or DC pseudo-op to determine the amount of
storage required.
EVAL Evaluate an arithmetic expression consisting of constants and
symbols.
STGET Search the symbol table(ST) for the entry corresponding to a specific
symbol.
8/3/2016jaya
ASSEMBLER
 Look for modularity
 PASS2
30
FUNCTION DESCRIPTION
READ2 Read the next assembly source card from the file copy.
POTGET2 Search the pass 2 pseudo-op table(POT) for a match with the operation
field of the current source card.
MOTGET2 Search the machine –op table (MOT) for a match with the operation of the
current source card.
EVAL Evaluate an arithmetic expression consisting of constants and symbols.
PUNCH Convert generated instruction to card format.
PRINT Convert relative location and generated code to character format; print the
line along with copy of the source card.
DCGEN Process the fields of the DC pseudo-op to generate object code.
DLENGTH Scan operand field of DS or DC pseudo-op to determine the amount of
storage required.
BTSTO Insert data into appropriate entry of Base Table(BT).
BTDROP Insert “unavailable” indicator into appropriate entry of BT.
BTGET Convert affective address into base and displacement by searching BASE
Table (BT) for available base registers.
LTGEN Generate code for literals(uses DCGEN)
8/3/2016jaya

Assembler1

  • 1.
  • 2.
    ASSEMBLER FUNCTION OF ANASSEMBLER ASSEMBLY LANG. PROGRAM DATABASE ASSEMBLER MACHINE LANG. & OTHER INFORMATION FOR LOADER 2 8/3/2016jaya
  • 3.
    ASSEMBLER  General formatfor assembly language statement Example: JOHN START 0 FOUR DC F’4’ A 2,FOUR Opcode ------- 1 digit Register operand ---------- 1 digit Memory operand ---------- 3 digits [Label *] [opcode] [operand1]*, [operand2]* 3 8/3/2016jaya
  • 4.
    ASSEMBLER  LABEL FIELD whenprocessed by assembler it will store this label and its information. Example: JHON DATA 4 8/3/2016jaya
  • 5.
    ASSEMBLER  Mnemonic OpcodeField instructions  Types of assembly statements Imperative statements Declarative statements Directive statements 5 8/3/2016jaya
  • 6.
    ASSEMBLER  Imperative statements Specifiesthe operation to be performed during the execution of program Example: MOVEM AREG , B MOVER AREG , C ADD AREG , ONE COMP AREG , =‘1’ SUB BREG , =‘2’ constant memory register 6 8/3/2016jaya
  • 7.
    ASSEMBLER  Declarative Statements declareconstant or storage variable  Types of declarative statements:-  DS(Declare Storage) ex: AB DS 1 X DS 200  DC(Declare Constant) ex: ONE DC 1 name 1 word mem. 7 8/3/2016jaya
  • 8.
    ASSEMBLER  Assembler Directivestatements or pseudo ops It specifies the operation to be performed during the process of assembly .  Types of pseudo opcodes  START  END  LTORG  ORIGIN  EQU 8 8/3/2016jaya
  • 9.
    ASSEMBLER  START  Tellsthe start of program  Gives name to program  Sets LC  ex: TEST START JHON START 484 9 8/3/2016jaya
  • 10.
    ASSEMBLER  END  Tellsend of program.  Ex: END  LTORG  Tells the assembler to place the literals at an earlier location  Used in very long programs  Ex: LTORG 10 8/3/2016jaya
  • 11.
    ASSEMBLER  ORIGIN used toreset location counter default value of reset is LC=0 Ex: ORIGIN <address space> 11 8/3/2016jaya
  • 12.
    ASSEMBLER  EQU allows todefine variable Syntax: <symbol> EQU <address space> Ex: BASE EQU 15 12 8/3/2016jaya
  • 13.
    ASSEMBLER  Operand Field withthis assembler perform actions  Types of operands Register Symbol Literal 13 8/3/2016jaya
  • 14.
    ASSEMBLER  Advantages ofassembler  Unambiguous code and compact  As close to machine as possible  Extremely fast  Compiled assembly programs are small  Storage can be allocated and deallocated dynamically. 14 8/3/2016jaya
  • 15.
    ASSEMBLER  Advantages ofassembly Language  Easy to memorize  Mnemonic opcodes are helpful for diagnostics  Program modification is easy  Manual conversion of constants into machine representation 15 8/3/2016jaya
  • 16.
    ASSEMBLER  General DesignProcedure  Specify the problem  Specify data structure  Define format of data structure  Specify algorithm  Look for modularity  Repeat 1 through 5 on modules 16 8/3/2016jaya
  • 17.
    ASSEMBLER  Statement ofproblem  Processing of each assembly instruction varies depending upon types of instruction.  Processing of each assembly instruction assembler processes each field of instruction.  In this labels or symbols can appear before they are defined, so it is convenient to make two passes over the input.  Passes of assembler  Pass 1  Pass2  Generate instructions (basic requirement)  Evaluate the mnemonic in the operation field to produce its machine code  Evaluate the subfields-find the value of each symbol, process literals and assign addresses.  Process pseudo ops 17 8/3/2016jaya
  • 18.
    ASSEMBLER  Pass1: purpose- define symbol and literals  Determine length of machine instructions(MOTGET1)  Keep track of Location Counter(LC)  Remember values of symbols until pass 2(STSTO)  Process some pseudo ops , e.g. EQU, DS (POTGET1)  Remember literals(LITSTO)  Pass2: purpose - generate object program  Look up value of symbols(STGET)  Generate instructions(MOTGET2)  Generate data(for DS, DC, and literals)  Process pseudo ops(POTGET2) 18 8/3/2016jaya
  • 19.
    ASSEMBLER  DATA STRUCTURES secondstep of design procedure for assembler  Pass 1 data base:  Input source program  A Location Counter(LC),  The Machine Opcode Table(MOT)  The Pseudo Opcode Table(POT)  The Symbol Table(ST)  The Literal Table(LT)  A copy of input used b pass2 19 8/3/2016jaya
  • 20.
    ASSEMBLER  DATA STRUCTURES secondstep of design procedure for assembler  Pass 2 data base:  Copy of source program input to pass 1  A Location Counter(LC),  The Machine Opcode Table(MOT)(mnemonic, length, binary m/c opcode and format)  The Pseudo Opcode Table(POT)  The Symbol Table(ST)  The Base Table(BT)  A workspace , INST  A workspace, PRINT LINE  A workspace PUNCH CARD  Output deck of assembled instruction 20 8/3/2016jaya
  • 21.
    ASSEMBLER  MOT(Machine Op-codeTable) 21 Mnemoni c opcode (4 bytes) (char) Binary opcode (1 byte) (hexadecimal) Instruction Length (2 bits) (binary) Instruction Format (3 bit) (binary) Not used in this design (3 bits) “Abbb” 5A 10 001 “AHbb” 4A 10 001 “ALbb” 5E 10 001 “ALRb” 1E 01 000 “ARbb” 1A 01 000 -------------- ------------ -------------- -------------- “MVCb” D2 11 100 000 RR 001 RX 010 RS 011 SI 100 SS Instruction format 01 1 half words 2 bytes 10 2 half words 4 bytes 11 3 half words 6 bytes Instruction length 6 bytes 8/3/2016jaya
  • 22.
    ASSEMBLER  MOT example 22 NAMEMNEMONIC BINARY OPCODE FORMA T OPERANDS Add(c) AR 1A RR R1,R2 Add (c ) A 5A RX R1,D2(X2,B2) Branch & link BALR 05 RR R1,R2 Start I/O SIO 9C SI D1(B1) Move MVC D2 SS D1(L,B1),D2(B2) 8/3/2016jaya
  • 23.
    ASSEMBLER  POT (pseudoopcode table) 23 PSEUDO OPCODE (5 BYTES CHAR) ADDRESS OF ROUTINES TO PROCESS PSEUDO OP (3 BYTES=24 BIT ADDRESS ”DROPb” P1 DROP “ENDbb” P1 END “EQUbb” P1 EQU “START” P1 START “ORIGIN” P1 USING 8/3/2016jaya
  • 24.
    ASSEMBLER  ST(symbol table)14 bytes per entry 24 SYMBOL (8 BYTES CHAR) VALUE (4 BYTE) HEXADECIMAL LENGTH (1 BYTE) HEXADECIMAL RELOCAT ION (1 BYTE) CHAR “SSSSbbbb” 0000 01 “R” “FOURbbbb” 0000 04 “R” “FIVEbbbb” 0010 04 “R” “TEMPbbbb” 0014 04 “R” 14 bytes per entry 8/3/2016jaya
  • 25.
    ASSEMBLER  LT(Literal table)14 bytes per entry 25 LITERAL (8 BYTES CHAR) VALUE (4 BYTE) HEXADECIMAL LENGTH (1 BYTE) HEXADECIMAL RELOCAT ION (1 BYTE) CHAR A(DATA1) 0048 04 “R” F’800’ 0060 04 “R” 8/3/2016jaya
  • 26.
    ASSEMBLER  BT(Base Table)15 entries 26 AVAILABILITY INDICATOR (1 BYTE) CHAR DESIGNED RELATIVE ADDRESS CONTENTS OF BASE REGISTER (3 BYTES = 24 BIT ADDRESS) HEXADECIMAL “N” ------------------ “N” ----------------- ----------------------- ----------------- “N” ---------- “Y” 00 00 00 N =register specified in USING Y= never specified 8/3/2016jaya
  • 27.
    Pass 1 LC 0 Read card from file copy READ1 Assign value to symbol in label field STSTO L  length Process any literals, enter into literal table LTSTO Write copy of card on file for use by pass2 WRITE1 Search pseudo-op table POTGET1 Which one ? Adjust LC to proper alignment L  length of data field DLENGTH Assign current value of LC to symbol STSTO Evaluate operand field EVAL Search machine-op table MOTGET1 Assign storage locations to literals LITASS Rewind and reset copy file On to pass 2 found DS DC NO EQU USING , DROP END Not found YES LC  LC + L Is there symbol in label field 8/3/2016jaya
  • 28.
    Pass 2 LC 0 Read card from file copy READ2 Enter base reg. no. and value into base table BTSTO Get op-code byte and format code L  length Type of instruction Evaluate both register expressions and insert into 2nd byte EVAL “punch” Assembled instruction PUNCH “print” assembly listing line PRINT LC  LC + L Search pseudo-op table POTGET2 Which one ? Adjust LC to proper alignment L  length of data field DLENGTH DC or DS Evaluate register and index expressions and insert into 2nd byte EVAL Calculate effective address(EA) of operand EVAL Determine appropriate displacement and base register D +C(B) =CA BTGET Put B & D into bytes 3 and 4 From constant and insert in assembled program DCGEN Evaluate operand EVALSearch pseudo-op table MOTGET2 Print listing PRINT Indicate base reg. no. unavailable BTDROP Generate literals for entries in literal table LTGEN STOP a b a b found DS DC DC DS EQU STAR T USING DROP END Not found RX RR 8/3/2016jaya
  • 29.
    ASSEMBLER  Look formodularity  PASS1 29 FUNCTIO N DESCRIPTION READ1 Read the next assembly source card. POTGET1 Search the pass 1 pseudo-op table(POT) for a match with the operation field of the current source card. MOTGET1 Search the machine –op table (MOT) for a match with the operation of the current source card. STSTO Store a label and its associated value into the symbol table (ST) LTSTO Store a literal into the literal table(LT) WRITE1 Write a copy of the assembly source card on a storage device for use by pass 2 DLENGTH Scan operand field of DS or DC pseudo-op to determine the amount of storage required. EVAL Evaluate an arithmetic expression consisting of constants and symbols. STGET Search the symbol table(ST) for the entry corresponding to a specific symbol. 8/3/2016jaya
  • 30.
    ASSEMBLER  Look formodularity  PASS2 30 FUNCTION DESCRIPTION READ2 Read the next assembly source card from the file copy. POTGET2 Search the pass 2 pseudo-op table(POT) for a match with the operation field of the current source card. MOTGET2 Search the machine –op table (MOT) for a match with the operation of the current source card. EVAL Evaluate an arithmetic expression consisting of constants and symbols. PUNCH Convert generated instruction to card format. PRINT Convert relative location and generated code to character format; print the line along with copy of the source card. DCGEN Process the fields of the DC pseudo-op to generate object code. DLENGTH Scan operand field of DS or DC pseudo-op to determine the amount of storage required. BTSTO Insert data into appropriate entry of Base Table(BT). BTDROP Insert “unavailable” indicator into appropriate entry of BT. BTGET Convert affective address into base and displacement by searching BASE Table (BT) for available base registers. LTGEN Generate code for literals(uses DCGEN) 8/3/2016jaya