0% found this document useful (0 votes)
41 views34 pages

System Software

This document outlines chapters from a textbook on system software. It focuses on Chapter 2 which discusses assemblers. The key points are: - Assemblers take source code and convert it to object code using tables and logic. They perform basic functions like handling literals, symbols, expressions and program structure. - Machine-dependent features include handling instruction formats and addressing modes as well as program relocation. - Machine-independent features include literals, symbol definitions, expressions, program blocks and control sections. Literals assign addresses to constants while avoiding duplicate values. Symbols and expressions define values in a readable way. - Assemblers typically use one or two passes to evaluate all symbols and expressions, gather literals,

Uploaded by

yashu J
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
0% found this document useful (0 votes)
41 views34 pages

System Software

This document outlines chapters from a textbook on system software. It focuses on Chapter 2 which discusses assemblers. The key points are: - Assemblers take source code and convert it to object code using tables and logic. They perform basic functions like handling literals, symbols, expressions and program structure. - Machine-dependent features include handling instruction formats and addressing modes as well as program relocation. - Machine-independent features include literals, symbol definitions, expressions, program blocks and control sections. Literals assign addresses to constants while avoiding duplicate values. Symbols and expressions define values in a readable way. - Assemblers typically use one or two passes to evaluate all symbols and expressions, gather literals,

Uploaded by

yashu J
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/ 34

MODULE 1

SYSTEM SOFTWARE
OUTLINE

• Chapter 1: Introduction
• Chapter 2: Assemblers
• Chapter 3: Macroprocessors

Text book 1: System Software by Leland. L. Beck, D


Manjula, 3rd edition, 2012
Chapter 1: 1.1,1.2,1.3.1,1.3.2,
Chapter2 : 2.1,2.2,2.3,2.4
Chapter4: 4.1.1,4.1.2
CHAPTER 2
ASSEMBLERS

Source Object
Assembler Linker
Program Code

Executable
Code

Loader
OUTLINE

• 2.1 Basic Assembler Functions


– A simple SIC assembler
– Assembler tables and logic
• 2.2 Machine-Dependent Assembler Features
– Instruction formats and addressing modes
– Program relocation
• 2.3 Machine-Independent Assembler Features
• 2.4 Assembler Design Options
– Two-pass
– One-pass
– Multi-pass
MACHINE-INDEPENDENT
ASSEMBLER FEATURES

1. LITERALS
2. SYMBOL-DEFINING STATEMENTS
3. EXPRESSIONS
4. PROGRAM BLOCKS
5. CONTROL SECTIONS AND PROGRAM
LINKING
2.3 MACHINE INDEPENDENT
ASSEMBLER FEATURES

• These are the features that are not


closely related to machine architecture.
• Common examples:
– Literals
– Symbol-defining statements
– Expressions
– Program blocks
– Control sections
2.3.1 LITERALS

• Literal is equivalent to:


– Define a constant explicitly and assign an
address label for it
– Use the label as the instruction operand
• Why use literals:
– To avoid defining the constant somewhere and
making up a label for it
– Instead, to write the value of a constant
operand as a part of the instruction
• How to use literals:
– A literal is identified with the prefix =, followed
by a specification of the literal value
ORIGINAL PROGRAM
USING LITERAL
OBJECT PROGRAM USING
LITERAL

The same as before


ORIGINAL PROGRAM
USING LITERAL
OBJECT PROGRAM USING
LITERAL

The same as before


LITERAL VS. IMMEDIATE ADDRESSING

• Same:
– Operand field contains constant values
• Difference:
– Immediate addressing: the assembler put the constant
value as part of the machine instruction
– Literal: the assembler store the constant value elsewhere
and put that address as part of the machine instruction
LITERAL POOL

• All of the literal operands are gathered together into


one or more literal pools.
• Where is the literal pool:
– At the end of the object program, generated immediately
following the END statement
– At the location where the LTORG directive is encountered
• To keep the literal operand close to the instruction that uses
it
DUPLICATE LITERALS
• Duplicate literals:
– The same literal used more than once in the
program
– Only one copy of the specified value needs to be
stored
– For example, there are two uses of =X’05’ on lines
215 and 230 respectively.
– How to recognize the duplicate literals
– Compare the character strings defining them
• Easier to implement, but has potential problem
• For example, =X’05’ and =X’05’
– Compare the generated data value
• Better, but will increase the complexity of the assembler
• E.g., =C’EOF’ and =X’454F46’
THE PROBLEM WITH STRING-DEFINING
LITERALS

• Allow literals that refer to the current value of the location counter.
– Such literals are sometimes useful for loading base registers.
LDB =*
; register B=beginning address of statement=current LOC
BASE *
; for base relative addressing
• If a literal =* appeared on line 13 and 55
– Specify an operand with value 0003 (Loc) and 0020 (Loc).
IMPLEMENTATION OF LITERAL

• Data structure: a literal table LITTAB


– Literal name
– Operand value and length
– Address
– Ex: Contains the literal name (=C’EOF’), the operand value (454F46)
and length (3), and the address (002D).
• LITTAB is often organized as a hash table, using the
literal name or value as the key
IMPLEMENTATION OF LITERAL

• Pass 1
– As each literal operand is recognized
• Search the LITTAB for the specified literal name or value
• If the literal is already present, no action is needed
• Otherwise, the literal is added to LITTAB (store the name,
value, and length, but not address)
– As LTORG or END is encountered
• Scan the LITTAB
• For each literal with empty address field, assign the address
and update the LOCCTR accordingly
IMPLEMENTATION OF LITERAL
• Pass 2
– As each literal operand is recognized
• Search the LITTAB for the specified literal name or value
• If the literal is found, use the associated address as the operand of
the instruction
• Otherwise, error (should not happen)
– As LTORG or END is encountered
• insert the data values of the literals in the object program
– Modification record is generated if necessary
2.3.2 SYMBOL-DEFINING
STATEMENTS
• How to define symbols and their values
– Address label
• The label is the symbol name and the assigned
address is its value
FIRST STL RETADR
– Assembler directive EQU
symbol EQU value
• This statement enters the symbol into SYMTAB and
assigns to it the value specified
• The value can be a constant or an expression
– Assembler directive ORG
ORG value
USE OF EQU
• To improve the program readability, avoid using the magic numbers, make it
easier to find and change constant values
– Replace
+LDT #4096
– with
MAXLEN EQU 4096
+LDT #MAXLEN
– Registers A, X, L can be used by numbers 0, 1, 2.

– The standard names reflect the usage of the registers.


BASE EQU R1
COUNT EQU R2
INDEX EQU R3
USE OF ORG

• Indirect value assignment:


ORG value
– When ORG is encountered, the assembler resets its
LOCCTR to the specified value
– ORG will affect the values of all labels defined until the
next ORG
– If the previous value of LOCCTR can be automatically
remembered, we can return to the normal use of LOCCTR
by simply write
ORG
EXAMPLE OF USING ORG
• Consider the following data structure
– SYMBOL: 6 bytes
– VALUE: 3 bytes (one word)
– FLAGS: 2 bytes
• we want to refer to every field of each
entry
NOT USING ORG

Offsets from STAB


Less readable and
meaningful

• We can fetch the VALUE field by


LDA VALUE,X
• X = 0, 11, 22, … for each entry
USING ORG
Set the LOCCTR to STAB

Size of field
more meaningful

Restore the LOCCTR to its


previous value
FORWARD-REFERENCE
PROBLEM
• Forward reference is not allowed for EQU and ORG.
• That is, all terms in the value field must have been
defined previously in the program.
• The reason is that all symbols must have been
defined during Pass 1 in a two-pass assembler.

Allowed

Not allowed
FORWARD-REFERENCE
PROBLEM

Not allowed

Not allowed
2.3.2 EXPRESSIONS
• A single term as an instruction operand can be
replaced by an expression.
STAB RESB 1100

STAB RESB 11*100

STAB RESB (6+3+2)*MAXENTRIES


• The assembler has to evaluate the expression to
produce a single operand address or value.
• Expressions consist of
– Operator
• +,-,*,/ (division is usually defined to produce an integer
result)
– Individual terms
• Constants
• User-defined symbols
• Special terms, e.g., *, the current value of LOCCTR
RELOCATION PROBLEM IN
EXPRESSIONS
• Values of terms can be
– Absolute (independent of program location)
• constants
– Relative (to the beginning of the program)
• Address labels
• * (value of LOCCTR)
• Expressions can be
– Absolute
• Only absolute terms
• Relative terms in pairs with opposite signs for each pair
– Relative
• All the relative terms except one can be paired as described in
“absolute”. The remaining unpaired relative term must have a positive
sign.
• No relative terms may enter into a multiplication or division
operation
• Expressions that do not meet the conditions of either “absolute”
or “relative” should be flagged as errors.
ABSOLUTE EXPRESSION
• Relative term or expression implicitly represents (S+r)
– S: the starting address of the program
– r: value of the term or expression relative to S
• For example
– BUFFER: S+r1
– BUFEND: S+r2
• The expression, BUFEND-BUFFER, is absolute.
– MAXLEN = (S+r2)-(S+r1) = r2-r1 (no S here)
– MAXLEN means the length of the buffer area
• Illegal expressions: BUFEND+BUFFER, 100-BUFFER,
3*BUFFER

Values associated with symbols


ABSOLUTE OR RELATIVE

• To determine the type of an expression, we


must keep track of the types of all symbols
defined in the program.
• We need a “flag” in the SYMTAB for indication.
THANK YOU

You might also like