0% found this document useful (0 votes)
23 views21 pages

Sys Software Mod 2 Updated Notes

The document provides an overview of assemblers, specifically focusing on the SIC and SIC/XE programming models. It details the functions of assemblers, including converting assembly language to machine code, handling assembler directives, and managing data structures like OPTAB and SYMTAB. Additionally, it discusses machine-dependent features such as instruction formats and addressing modes, as well as machine-independent features like literals and control sections.

Uploaded by

ashihabutheen96
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)
23 views21 pages

Sys Software Mod 2 Updated Notes

The document provides an overview of assemblers, specifically focusing on the SIC and SIC/XE programming models. It details the functions of assemblers, including converting assembly language to machine code, handling assembler directives, and managing data structures like OPTAB and SYMTAB. Additionally, it discusses machine-dependent features such as instruction formats and addressing modes, as well as machine-independent features like literals and control sections.

Uploaded by

ashihabutheen96
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

ASSEMBLER

• Assembler is a program that converts assembly language into machine code.


• Each assembly language is designed for a specific processor.

SIC PROGRAMMING
Q: Sample data movement operation in SIC
LDA FIVE
STA ALPHA
FIVE WORD 5
ALPHA RESW 1
RESW & WORD are assembler directives.

Q: Sample data movement operation in SIC/XE


LDA #5
STA ALPHA
ALPHA RESW 1

Q: Difference between instruction LDA FIVE and LDA #5.


o Both are used to load a value to the accumulator register. LDA FIVE is
an instruction in SIC. LDA #5 is an instruction in SIC/XE
o LDA #5 represent immediate addressing used to pass value 5 to
accumulator.
BASIC ASSEMBLER FUNCTIONS

The basic assembler functions are:


o Assembler converts the assembly language into machine language.
o The main function of an assembler is assigning addresses to labels.
o The output of the assembler program is the object program, a machine
language translation of the source program.

Q: List various assembler functions


Basic Assembler Functions (Imp)
• Convert mnemonic operation codes to machine
• Convert symbolic operands to machine addresses (pass 1)
• Build machine instructions
• Convert data constants to internal representations
• Write the object program and assembly listing files

Q: What are Assembler directives


Assembler directives are pseudo instructions. These instruct the assembler to perform
certain instructions during the assembly.

Q: List various assembler directives.


SIMPLE SIC ASSEMBLER-ASSEMBLER ALGORITHM AND DATA
STRUCTURES

OBJECT RECORD/ OBJECT PROGRAM FORMAT

Q: Explain object program format or assembler output format or what are the different
types of records in object program.
Assembler must write generated object code to some output device. The object
program will later be loaded into memory for execution.

Object program format contains three types of records:


1. Header record: Contains the program name, starting address and length.
2. Text record: Contains the machine code and data of the program.
3. End record: Marks the end of the object program and specifies the address in the
program where execution is to begin.

Q: What are the functions of two passes of SIC assembler


Functions of two passes of a simple SIC assembler
Q: What is forward reference
A forward reference is an issue occurring in the conversion of symbolic operands to
machine address. A forward reference is the reference to the label which is defined
later in the source program. Hence we need to use a two pass assembler. The first
pass scans the source program for label definitions and assign addresses. Second pass
perform actual translation.

DATA STRUCTURES IN ASSEMBLERS

Q: What are the various data structure used in SIC assembler.


• Simple assembler uses three major internal data structures:
OPTAB- Operation Code Table
SYMTAB- Symbol Table
LOCCTR- Location Counter

ALGORITHM FOR PASS1 AND PASS2 ASSEMBLER(Very Very Imp)

Q: Write Algorithm for Pass1 and Pass2 assemblers(Essay)


MACHINE DEPENDENT ASSEMBLER FEATURES- INSTRUCTION
FORMAT AND ADDRESSING MODES, PROGRAM RELOCATION

Q: What are machine dependent assembler features?


• Each assembly language is designed for a specific processor.
• Machine-dependent assembler features, like instruction formats and addressing
modes, are specific to the architecture of a computer.
• Instruction formats define how instructions are structured, including the number and
arrangement of fields like opcode and operand addresses.
• Addressing modes determine how operands are accessed
• 2 main machine dependent assembler features are
1. INSTRUCTION FORMATS AND ADDRESSING MODES
2. PROGRAM RELOCATION.

1.INSTRUCTION FORMATS & ADDRESSING MODES

Instruction Format
• An instruction format defines layout of instruction
• Each assembly language statement is split into an opcode and an operand.
• The opcode is the instruction that is executed by the CPU and the operand is the data
or memory location used to execute that instruction.
• Format must, implicitly or explicitly, indicate addressing mode for each operand.

General Instruction Format


Opcode_Field Address_Field

Format 1 instruction is 1byte (8 bits) long


It contains only the opcode- no operands, no registers, no addressing modes are
present.
Eg: SIO (Start Input/Output Operations)

Format 2 instruction is 2 bytes (16 bits) long and includes:


Operation code (opcode) represents 8 bits
Register operands are (4 bits+4 bits)
Eg: ADDR A, X Add register A to X

Format 3 instruction is a 3-byte (24-bit) instruction used for memory reference operations.
It includes:
Opcode (6 bits)
Addressing mode flags (n, i, x, b, p, e)(6 bit)
Displacement/address (12 bits)
Eg: LDA #5

Format 4 instruction is an extended version of Format 3.


It allows direct addressing of full 20-bit memory addresses, enabling access to a much
larger address range
Eg: +LDX 4096
Main advantage of SIC/XE over SIC is that register to register operations are faster than
memory access operations.

Addressing modes
• The different ways in which location of an operand is specified in an instruction are
referred to as “Addressing Modes”.
• Different addressing modes used are:
i) Immediate addressing
ii) Indirect addressing
iii)Indexed addressing
iv)PC-relative or Base relative addressing
v)Register addressing
vi)Extended format addressing

i)Immediate addressing(#)
Here the operand's value is directly included within the instruction itself, rather than
being stored in memory or a register. A hash symbol (#) is often used to denote immediate
values. This means no memory access is needed to fetch the operand, making it a fast
operation.
Eg: LDA #10, Loads the value 10 directly into register A.

ii)Indirect addressing(@)
Often indicated by the "@" symbol or parentheses, is an addressing mode where the
address field of an instruction doesn't directly contain the operand's address but rather the
address of a memory location.
Eg: LDA @TABLE, Fetches the address from TABLE, then loads the value from that
address.

iii)Indexed addressing
It calculates the effective memory address by adding an index value (typically from an
index register) to a base address. This method is particularly useful for accessing elements
within arrays or tables in memory
Eg: LDA TABLE, X means loads from the address TABLE + X.

iv)Base Relative Addressing or PC relative addressing


It is a method used in computer programming where the effective address of an
operand is calculated by adding a displacement to the contents of a base register
The base register holds the starting address of the structure, and the displacement specifies
the offset of the desired element from that starting point.
BASE TABLE
LDA VALUE

v)Extended format addressing


Extended format (Format 4) addressing associated with the SIC/XE architecture, is a
memory addressing mode that allows for a larger address space.
Eg: +JSUB SUBROUTINE

vi)Register addressing
Involves the use of registers to hold the data to be manipulated. In this addressing
mode, a register contains the operand.
Eg : MOV A, R0
MOV R1, R0

Q: What is difference between absolute addressing and relative addressing.


Absolute addressing specifies the exact physical memory location of data or
instructions, while relative addressing calculates memory addresses based on a starting point .

2.PROGRAM RELOCATION
• Program relocation is the process of modifying the address‑dependent parts of a
program so it can execute correctly when loaded at an different address.
• Sometimes it is required to load and run several programs at the same time.
• The system must be able to load these programs wherever there is place in the
memory.
• Therefore the exact starting is not known until the load time.

Absolute Program :In this the address is mentioned during assembling itself. This is called
Absolute Assembly.

Consider the instruction:


55 101B LDA THREE 00102D
• It says that the register A is loaded with the value stored at location 102D. (starting
1000)
• Suppose it is decided to load and execute the program at location 2000 instead of
location 1000.
• Then at address 102D the required value which needs to be loaded in the register A is
no more available.
• An object program that has the information necessary to perform this kind of
modification is called the relocatable program.
• Relocatable program is loaded at location 0000.
• The only part of the program that require modification at load time are those that
specify direct addresses.
• The instructions which doesn’t require modification are the ones having immediate
addressing.
• The object program that contains the modification record is called a relocatable
program.
• The assembler produces a Modification record to store the starting location and the
length of the address field to be modified.
The Modification has the following format: (Q: What is the format of modification record.

Modification record
Col. 1 M
Col. 2-7 Starting location of the address field to be modified, relative to the beginning
of the program (Hex)
Col. 8-9 Length of the address field to be modified, in half-bytes (Hex)
One modification record is created for each address to be modified.

MACHINE INDEPENDENT ASSEMBLER FEATURES- LITERALS,


SYMBOL DEFINING STATEMENTS, EXPRESSIONS

• These are the features which do not depend on the architecture of the machine.
1. LITERALS
2. SYMBOL DEFINING STATEMENTS
3. EXPRESSIONS
4. PROGRAM BLOCKS
5. CONTROL SECTIONS AND PROGRAM LINKING

1. LITERALS
• Literals are used to write the value of a constant operand as a part of instruction that
uses it.
• So need not have to define the constant elsewhere and make a label for it.
• Literal is defined with prefix =, followed by a specifying literal value.

Line Loc Label mneumonic/opcode Operand ObjectCode


215 1062 WLOOP TD =X'05' E32011
• Second instruction specifies a 1byte literal with hexadecimal value 05.

Q: Difference between literal and immediate operand.


• With immediate addressing operand value is assembled as part of instruction.
Eg: LDA #5
• With literal, assembler generate specified value as a constant.
Eg: TD =X'05'
• All literal operands are gathered together into one or more literal pools.
• Literal pool are placed at the end of the program.
• Literal pool consist of literals along with assigned address and data values.
• Literal pool instead of placing at the end can be also placed at some other location, it
is done using the assembler directive LTORG.
(Q: What is the use of assembler directive LTORG.)
• LTORG create a literal pool with all literal operands immediately.
• To handle literal pool, datastructure called literal table LITTAB is used.
(Q: What is the use of datastructure LITTAB)
• LITTAB is a datastructure that contains literal name, operand value and length and
address assigned to operand when placed in literal pool.
• LITTAB is organised as a hash table using literal name as the key.
• The LTORG directive in assembly language programming instructs the assembler to
assemble the current literal pool immediately.
• During Pass1,
Literal encountered search in LITTAB
If literal exists do nothing
else
literal added to LITTAB
Search for address till LTORG is found
Update LOCCTR

• During Pass2
Assembler search LIITAB for each literal and replace with equivalent value

2. SYMBOL DEFINING STATEMENTS


Assemblers provide an assembler directive that allows programmer to define
symbols and specify values called EQU

EQU
EQU is an assembler directive used to define symbols and specify their values

symbol EQU values


• This statement define given symbol and assigns value specified
• Value may be constant or an expression with constant and symbols
• EQU used to improve readability.

Eg: LDA #J
J EQU 5

• EQU used to define mnemonic names for registers.


Eg:
A EQU 0
X EQU 1

• ORG is another assembler directive used to indirectly assign values to symbols.


Used to assign starting address for a modules or segment

ORG value
Eg: ORG 1050H
• By this instruction, the assembler gets to know that the statements following this
instruction, must be stored in the memory location beginning with address 1050H.

3. EXPRESSIONS
• Expressions consist of one or more integer literals or symbol references, combined
using operators.
• Each expression must be evaluated to produce a single operand address or value
• Two types of expression
Absolute expression
Relative expression
Absolute Expressions: The expression that uses only absolute terms is absolute
expression
Eg: MAXLEN EQU 1000
The value 1000 does not depend on the location of the program

Relative expression: A relative expression is one whose value depends on the


program's starting address (i.e., relocatable).
Its value changes when the program is loaded at a different memory location
MAXLEN EQU BUFEND-BUFFER

Q: What is meant by the instruction given below..??

BUFFEND EQU *

The only special term used is *, which shows current value of LOCCTR, or the
next unassigned memory location.

4. PROGRAM BLOCKS
• Program blocks are segments of code that are rearranged within a single object
program unit
• Consider program divided into 3 blocks:
o Default block- all executable instructions
o CDATA block- all data areas with few words
o CBLKS block-all data areas with larger blocks of memory
• Assembler directive USE indicate which portion of source program belongs to
various blocks
o USE [blockname]

• If no USE statement, entire instruction belong to a single block.


• Each block will be assigned address in object program
5. CONTROL SECTIONS AND PROGRAM LINKING
• A control section is a part of the program that maintains its identity after assembly;
each control section can be loaded and relocated independently of the others.
• The programmer can assemble, load, and manipulate each of these control sections
separately.
• Because of this, there should be some means for linking control sections together
• For example, instructions in one control section may refer to the data or instructions
of other control sections
• Since control sections are independently loaded and relocated, the assembler is unable
to process these references in the usual way.
• Such references between different control sections are called external references.
• Beginning of each of the control section is indicated by an assembler directive –
assembler directive: CSECT

Syntax
secname CSECT
Eg: RDREC CSECT
• The external references are indicated by two assembler directives:
EXTDEF
EXTREF

EXTDEF (external Definition):


It is the statement in a control section, names symbols that are defined in this section
but may be used by other control sections.
Eg: EXTDEF BUFFER, BUFFEND

EXTREF (external Reference):


It names symbols that are used in this section but are defined in some other control
section.
Eg: EXTREF REDREC, WRREC

• For proper assembly of control sections assembler maintains two new records in the
object code
Define record
Refer record
Define record (EXTDEF)
A define record gives information about the external symbols that are defined in this
control
section, i.e., symbols named by EXTDEF.

Col. 1 D
Col. 2-7 Name of external symbol defined in this control section
Col. 8-13 Relative address within this control section (hexadecimal)
Col.14-73 Repeat information in Col. 2-13 for other external symbols

Refer record (EXTREF)


A refer record lists the symbols that are used as external references by the control
section, i.e., symbols named by EXTREF.

Col. 1 R
Col. 2-7 Name of external symbol referred to in this control section
Col. 8-73 Name of other external reference symbols

ASSEMBLER DESIGN OPTIONS-ONE PASS ASSEMBLERS AND MULTI


PASS ASSEMBLERS

• An assembler is a program that converts assembly language into machine code.


• It takes the basic commands and operations from assembly code and converts them
into binary code that can be recognized by a specific type of processor.
• There are many types of assembler
ONE PASS ASSEMBLER(LOAD AND GO ASSEMBLER)
TWO PASS ASSEMBLER
MULTI PASS ASSEMBLER

ONE PASS ASSEMBLER


• A single pass assembler scans the program only once and creates the equivalent
binary program.
• The assembler substitute all of the symbolic instruction with machine code in one
pass .
• Single pass assemblers are used when
o It is necessary or desirable to avoid a second pass over the source program
o The external storage for the intermediate file between two passes is slow .

Forward References Problem in One Pass Assembler


Rules for an assembly program states that the symbol should be defined somewhere in
the program. But in some cases a symbol may be used prior to its definition. Such a reference
is called forward reference. It handles forward references by storing incomplete instructions
in a table and resolving them when the corresponding symbols are defined
Load-and-Go Assemblers:(Single pass assembler)
• Some single-pass assemblers are designed as "load-and-go" assemblers.
• These assemblers directly load the translated machine code into memory for
immediate execution, without creating a separate object file.
• This approach is beneficial in environments where frequent program execution is
required.

TWO PASS ASSEMBLER

• In two pass assembler Processing of source program can be done in two passes.
• The internal tables and subroutines that are used only during Pass 1.
• The main problems to assemble a program in one pass involves forward references. It can
eliminate in two pass assembler by doing the conversion in two separate passes

PASS 1 Operations
• Assign addresses to all statements in the program.
• Addresses of symbolic labels are stored.

PASS 2 Operations
• Translate opcode and symbolic operands.
• Generate data values defined by BYTE,WORD etc.
• Assemble directives will be processed.
• Write the object program and assembly listing.

MULTIPASS ASSEMBLER
• A multi-pass assembler is an assembler that scans the source program multiple times
(more than two passes) to handle complex situations such as forward references,
complex expressions, macros, conditional assembly, and external references that
cannot be resolved in just one or two passes.
• This approach is necessary when the assembler needs to resolve forward references,
where a symbol is used before it is defined in the code.
JUMP target
...
target: ADD R1, R2

Benefits of Multi-Pass Assemblers:


• Handles Forward References: Allows for more flexibility in writing assembly code
by not restricting symbol definitions to a specific order.
• Increased Efficiency: Multiple passes can allow for better code optimization.
• Can handle complex programs with forward references, macros, or external links.
Q: Explain working of multipass assembler
Consider the following sets of instructions
ALPHA EQU BETA
BETA EQU DELTA
DELTA EQU 1
The symbol BETA cannot be assigned a value when it is encountered during first pass
as DELTA has not yet been defined. Hence ALPHA cannot be evaluated during second
pass. Thus a two pass assembler cannot resolve such a sequence of instructions.
Hence a multipass assembler can make as many passes as are needed to process
the definition of symbols. The method involves storing those symbol definitions that
involve forward reference in the symbol table.
IMPLEMENTATION EXAMPLE- MASM

• MASM stands for Microsoft Macro Assembler.


• It is a software tool developed by Microsoft for writing and assembling x86
assembly language programs.
• MASM converts assembly code (.asm) into machine code (.obj), which can be linked
to form executable files.
• Supports Macro Processing: Allows defining and using macros (short reusable code
blocks).
• MASM includes a macro language that allows developers to create reusable blocks of
code, which can simplify and organize complex programs

BASIC MACRO PROCESSOR FUNCTIONS- MASM- MACRO DEFINITION


AND EXPANSION

• A macro instruction represent a group of statements in source programming language.


• A macro allows to write shorthand version of a programmer
• Macro processor replace each macro instruction with corresponding group of source
language statements. This is called expanding the macros.
• Macro processor performs no analysis of the text it handles.
• Macroprocessor is also not concerned about the meaning of involved statements
during macro expansion.
• Design of macro processor is machine independent.
• Programmer of x86 views memory as a collection of segments
• Each segment is belonging to a particular class corresponding to its contents.
• Common classes are CODE, DATA, CONST, STACK.
• Code segments are addressed using CS.
• Register CS set to indicate the segment contains starting label specified in the END
statement.
• Register SS is set to indicate the last stack segment processed by loader.
• Data segments are addressed using DS, ES, FS, GS.
• A near jump is a jump to target in the same code segment, while a far jump is a
jump to a target in another code segment.

Q: What is the use of assembler directive ASSUME?


The ASSUME assembler directive is used to tell the assembler which logical segment
registers (like CS, DS, SS, ES) to use for specific segments in the assembly language
program.

Q: What are the functions of macro processor?


Macro definition, macro invocation and macro expansion(Refer below)

Basic functions of macroprocessor


• MACRO DEFINITION
• MACRO INVOCATION
• MACRO EXPANSION

MACRO DEFINITION
• Two new assembler directives are used in macro definition
MACRO: Identify the beginning of macro definition.
MEND: Identify the end of a macro definition.

Syntax
name MACRO &parameters
...
Body
...
MEND
• MACRO defines beginning of the macro definition.
• Entries in the operand field identify parameters of macro instruction.
• Each parameters always start with &.
• Body consist of statements that will be generated at the expansion of macro.
• MEND marks the end of macro definition.

Eg: WD MACRO
STA DATA1
STB DATA2
MEND

MACRO INVOCATION
• A macro invocation or a macro call gives name of macro instruction and the
arguments to be used in expanding the macro.
• A macro invocation is also called macro call.
• Each macro invocation statement has been expanded into the statements that
form the body of macro, with arguments from macro invocation substituted for
parameters in macro.
name &p1,&p2

MACRO EXPANSION
• Each macro invocation statements will be expanded into statements that form
the body of macro.
• A macro call leads to a macro expansion.
• Arguments from invocation are substituted for parameters.
• Comment lines in macro will be deleted.
• Label on macro invocation will be retained as label on macro expansion.
• All macro definitions are processed during first pass and all macro invocations
are expanded during second pass.

Q: Difference between macro call and subroutine call?


Macro call : statements are expanded each time the macro is invoked.
Subroutine/procedure call: statements of subroutine appear only once

Q: What are the different data structures in macro processor?


DEFTAB (Definition Table)
▪ Stores the macro definition including macro prototype and macro
body.
▪ Comments are omitted.
▪ References to macro instruction parameters are converted to
positional notation .

NAMTAB
▪ Store macro names
▪ Serves as key to DEFTAB
▪ Pointers to beginning and end of macro definition(DEFTAB)

ARGTAB (Argument Table)


▪ Used during expansion of macro invocations.
▪ Stores arguments of macro invocation according to position in
argument list.
▪ As macro is expanded arguments from ARGTAB are substituted
for corresponding parameters in macro body.

MACRO PROCESSOR SYSTEM SOFTWARE TOOLS(Old Syllabus)


Macro processor System software tools are used to process programs inside
computer system and that makes efficient execution of application software. The
following are the basic tool
1. Translator
A Translator is a system program that converts a program in one language to a
program in another language.
2. Assembler
Assembler is a language translator which takes as input a program in assembly
language of machine A and generates its equivalent machine code.
3. Compiler
A Compiler is a language translator that takes as input a source program in
some HLL and converts it into a lower-level language (i.e. machine or assembly
language). • So, an HLL program is first compiled to generate an object file with
machine-level instructions (i.e. compile time) and then instructions in object file are
executed (i.e. run time).
4. Interpreters
An Interpreter is similar to a compiler, but one big difference is that it executes
each line of source code as soon as its equivalent machine code is generated.
If there are any errors during interpretation, they are notified immediately to the
programmer and remaining source code lines are not processed.
5. Pre-processors
A Pre-processor converts one HLL into another HLL. Typically pre-processors
are seen as system software used to perform some additional functions (such as
removal of white spaces and comments) before the actual translation process can
begin.
6. Linker
A Linker (or a Linkage Editor) takes the object file, loads and compiles the
external sub routines from the library and resolves their external references in the
main-program. A Compiler generates an object file after compiling the source code.
But this object file cannot be executed immediately after it gets generated.
7. Loaders
A Loader does the job of coordinating with the OS to get the initial loading
address for the program, prepares the program for execution (i.e. generates an .exe
file) and loads it at that address. Also, during the course of its execution, a program
may be relocated to a different area of main memory by the OS (when memory is
needed for other programs). An important job of Loader is to modify these address-
sensitive instructions, so that they run correctly after relocation.

-----***----

You might also like