100% found this document useful (2 votes)
76 views

Assembler Dependent Features

The document discusses assemblers, which translate assembly language code into machine-readable object code. It covers both machine-dependent and machine-independent features of assemblers. Machine-dependent features include instruction formats, addressing modes, and program relocation. Machine-independent features include literals, symbols, expressions, program blocks, and linking. The document also describes one-pass and multi-pass assembler designs and provides examples of specific assemblers.

Uploaded by

Manasa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
76 views

Assembler Dependent Features

The document discusses assemblers, which translate assembly language code into machine-readable object code. It covers both machine-dependent and machine-independent features of assemblers. Machine-dependent features include instruction formats, addressing modes, and program relocation. Machine-independent features include literals, symbols, expressions, program blocks, and linking. The document also describes one-pass and multi-pass assembler designs and provides examples of specific assemblers.

Uploaded by

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

Module-2

Assemblers

1
Module 2 -- Outline
Machine Dependent Features –
• Instruction Formats & Addressing Modes
• Program Relocation.
Machine Independent Features –
• Literals
• Symbol Definition Statements
• Expression,
• Program Blocks
• Control Sections and Programming Linking
Assembler Design Operations –
• One-Pass Assembler
• Multi-Pass Assembler
Implementation Examples –
• MASM Assembler
• SPARC Assembler
2
Assembler Design
 Machine Dependent Assembler Features
 instruction formats and addressing modes
 program relocation

 Machine Independent Assembler Features


 literals
 symbol-defining statements
 expressions
 program blocks
 control sections and program linking

3
Machine-dependent
Assembler Features

 Instruction formats and addressing modes

 Program relocation

4
Instruction Format and Addressing Mode

 SIC/XE
 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)

5
 Instruction formats
8
Format 1 (1 byte) op

8 4 4
Format 2 (2 bytes) op r1 r2
e=0 Relative
6 1 1 1 1 1 1 12 addressing
Format 3 (3 bytes) op n i x b p e disp

e=1 Extended
6 1 1 1 1 1 1 20 addressing
Format 4 (4 bytes) op n i x b p e address

6
Translation
 Register translation
 register name (A, X, L, B, S, T, F, PC, SW) and their
values (0,1, 2, 3, 4, 5, 6, 8, 9)
 preloaded in SYMTAB

 Address translation
 Most register-memory instructions use program
counter relative or base relative addressing
 Format 3: 12-bit address field
 base-relative: 0~4095
 pc-relative: -2048~2047

 Format 4: 20-bit address field

8
Generate the object code for following SIC/XE program.
Op codes: LDCH= 50, STCH=54, JLT=38, LDT=74, LDX=04, TIXR=B8.

LOC Label Mnemonic Operand Object code Addressing


mode
STRCOPY START
LDX #0
LDT #5
LOOP LDCH STR1, X
STCH STR2, X
TIXR T
JLT LOOP
STR1 BYTE C’RNSIT’
STR2 RESB 5
END

9
Copy string ‘RNSIT’ from location STR1 to STR2
Find object code
LOC LABEL OPCODE OPERAND OBJECT CODE Addr. mode

---- COPY START 0

0000 FIRST LDX #0 050000 Immediate

0003 LDT #5 750005 Immediate

0006 LOOP LDCH STR1, X 53A008 Relative, indexed

0009 STCH STR2, X 57A00A Relative, indexed

000C TIXR T B850 Register

000E JLT LOOP 3B2FF5 Relative

0011 STR1 BYTE C’RNSIT’ 524E534954


0016 STR2 RESB 5
001B END
LDA=00, ADD=18, LDS=6C, LDT=74,MULR=98,SUBR=94,STA=0C

Address Label Mnemonic Operand Object code


STRCOPY START 0
0000 LDA #4
ADD BETA
LDS #9
LDT GAMMA
MULR S, T
SUBR T, A
STA ALPHA
BETA RESW 1
GAMMA RESW 1
ALPHA RESW 1
END
Address Label Mnemonic Operand Object code
STRCOPY START 0
0000 LDA #4 010004
0003 ADD BETA 1B200D
0006 LDS #9 6D0009
0009 LDT GAMMA 77200A
000C MULR S, T 9845
000E SUBR T, A 9450
0010 STA ALPHA 0F2006
0013 BETA RESW 1
0016 GAMMA RESW 1
0019 ALPHA RESW 1
001C END
Generate the object code for following SIC/XE program.
Op codes: CLEAR=B4, LDS=6C, LDA=00, LDB=68, ADD=18, TIXR=B8,
STA=0C, J=3C, RSUB=4C.
LOC SOURCE STATEMENT OBJECT CODE
0000 SUM START 0
0000 FIRST CLEAR X
0002 +LDS #4096
0006 LDA #0
0009 +LDB #TAB2
BASE TAB2
000D LOOP ADD TAB1, X
0010 TIXR S
0012 STA TAB2
0015 J @RETADR
0018 RSUB
001B RETADR RESW 1
001E TAB1 RESB 4096
101E TAB2 WORD 4096
1021 END FIRST
13
Find object code

LOC LABEL OPCODE OPERAND OBJECT CODE Addr. mode


---- SUM START 0
0000 FIRST CLEAR X B410 Register
0002 +LDS #4096 6D101000 Extended
0006 LDA #0 010000 Immediate
0009 +LDB #TAB2 6910101E Extended
---- BASE TAB2 Directive
000D LOOP ADD TAB1, X 1BA00E Relative, indexed

0010 TIXR S B840 Register


0012 STA TAB2 0F4000 Relative
0015 J @RETADR 3E2003 Indirect, Relative

0018 RSUB 4C0000 Simple


001B RETADR RESW 1
001E TAB1 RESB 4096
101E TAB2 WORD 4096 001000
1021 END FIRST
Program Relocation

 Absolute program is one which executes properly


only when the program is loaded from a specified
location.
 Absolute program, starting address 1000
e.g. 55 101B STL RETADR 141033

 Relocate the program to 2000


e.g. 55 101B STL RETADR 142033

 Each Absolute address should be modified

15
16
Program Relocation
 Program relocation is the ability of loading the
program in different memory location other than the
actual starting address

 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

17
18
19
Relocatable Program

 Modification record
 Col 1 M
 Col 2-7 Starting location of the address field to be
modified, relative to the beginning of the program
 Col 8-9 length of the address field to be modified, in half-
bytes

20
21
22
Object Code

23
Why Relative addressing need not
require modification?

24
TA = [PC] + disp
= 2003 + 02D
= 2030

25

You might also like