Docsity

System software unit ii, Lecture notes of System Programming

Toggle sidebar
bg1
KCG College of Technology,Chennai-96
Computer Science and Engineering
CS 1203 SYSTEM SOFTWARE III Sem CSE
QUESTION BANK - UNIT-II ASSEMBLERS
1) Why an Assembly Language is needed?
Programming in machine code, by supplying the computer with the numbers of the
operations it must perform, can be quite a burden, because for every operation the
corresponding number must be looked up or remembered. Looking up all numbers
takes a lot of time, and mis-remembering a number may introduce computer bugs.
So Assembly Languages are evolved which contains mnemonic instructions
corresponding to the Machine codes using which the program can be written easily.
Therefore a set of mnemonics was devised. Each number was represented by an
alphabetic code. So instead of entering the number corresponding to addition to add
two numbers one can enter "add".
Although mnemonics differ between different CPU designs some are common, for
instance: "sub" (subtract), "div" (divide), "add" (add) and "mul" (multiply).
2) What is an Assembler?
An assembler is a program that accepts an assembly language program as input and
produces its machine language equivalent along with information for the loader
(An Assembler translates a program written in an assembly language to it machine
language equivalent)
3) Explain the terms a)Label,b)Opcode,c)Operand,and d)Comment
(What is the format in which the assembly language program is written?).
•Label field.
• The label is a symbolic name that represents the memory address of an
executable statement or a variable.
•Opcode/directive fields.
•The opcode (e.g. operation code) specifies the symbolic name for a
machine instruction.
• The directive specifies commands to the assembler about the way to
assemble the program.
•Operand field.
• The operand specifies the data that is needed by a statement.
•Comment field.
• The comment provides clear explanation for a statement.
4) What are the basic functions of an assembler?
Functions of a Basic Assembler
• Convert mnemonic operation codes to their machine
language equivalents
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download System software unit ii and more Lecture notes System Programming in PDF only on Docsity!

KCG College of Technology,Chennai-

Computer Science and Engineering

CS 1203 SYSTEM SOFTWARE III Sem CSE QUESTION BANK - UNIT-II ASSEMBLERS

  1. Why an Assembly Language is needed? Programming in machine code, by supplying the computer with the numbers of the operations it must perform, can be quite a burden, because for every operation the corresponding number must be looked up or remembered. Looking up all numbers takes a lot of time, and mis-remembering a number may introduce computer bugs. So Assembly Languages are evolved which contains mnemonic instructions corresponding to the Machine codes using which the program can be written easily. Therefore a set of mnemonics was devised. Each number was represented by an alphabetic code. So instead of entering the number corresponding to addition to add two numbers one can enter "add". Although mnemonics differ between different CPU designs some are common, for instance: "sub" (subtract), "div" (divide), "add" (add) and "mul" (multiply).

  2. What is an Assembler? An assembler is a program that accepts an assembly language program as input and produces its machine language equivalent along with information for the loader (An Assembler translates a program written in an assembly language to it machine language equivalent)

  3. Explain the terms a)Label,b)Opcode,c)Operand,and d)Comment ( What is the format in which the assembly language program is written?).

  • Label field.
    • The label is a symbolic name that represents the memory address of an executable statement or a variable.
  • Opcode/directive fields.
    • (^) The opcode (e.g. operation code) specifies the symbolic name for a machine instruction.
    • The directive specifies commands to the assembler about the way to assemble the program.
  • Operand field.
    • The operand specifies the data that is needed by a statement.
  • Comment field.
    • The comment provides clear explanation for a statement.
  1. What are the basic functions of an assembler?

Functions of a Basic Assembler

  • Convert mnemonic operation codes to their machine language equivalents

E.g. STL -> 14 (line 10)

  • Convert symbolic operands to their equivalent machine addresses E.g. RETADR -> 1033 (line 10)
  • (^) Build the machine instructions in the proper format
  • Convert the data constants to internal machine representations E.g. EOF -> 454F46 (line 80)
  • Write the object program and the assembly listing
  1. What are assembler Directives? Assembler directives are Pseudo-instructions that are n ot translated into machine instructions and they provide instructions to the assembler itself.
  • The SIC assembler directives.
    • (^) START
      • Specification of the name and start address of the program.
    • END
      • Indication of the end of the program and optionally the address of the first executable instruction.
    • BYTE
      • Declaration of character or string constants.
    • WORD
      • Declaration of integer constants.
    • RESB
      • (^) Declaration of character variables or arrays.
    • RESW
      • Declaration of integer variables or arrays.
  1. What are the functions of two pass assembler?

Functions of Two Pass Assembler

  • Pass 1 - define symbols (assign addresses)
    • Assign addresses to all statements in the program
    • Save the values assigned to all labels for use in Pass 2
    • (^) Process some assembler directives
  • Pass 2 - assemble instructions and generate object program Assemble instructions
    • Generate data values defined by BYTE, WORD, etc.
    • Process the assembler directives not done in Pass 1
    • Write the object program and the assembly listing
  1. (^) What is the format of the Object Program generated by the Assembler? Contains 3 types of records: Header record: Col. 1 H

115. SUBROUTINE TO READ RECORD INTO BUFFER

125 2039 RDREC LDX ZERO 041030

130 203C LDA ZERO 001030

135 203F RLOOP TD INPUT E0205D

140 2042 JEQ RLOOP 30203D

145 2045 RD INPUT D8205D

150 2048 COMP ZERO 281030

155 204B JEQ EXIT 302057

160 204E STCH BUFFER,X 549039

165 2051 TIX MAXLEN 2C205E

170 2054 JLT RLOOP 38203F

175 2057 EXIT STX LENGTH 101036

180 205A RSUB 4C

185 205D INPUT BYTE X’F1’ F

190 205E MAXLEN WORD 4096 001000

200. SUBROUTINE TO WRITE RECORD FROM BUFFER

210 2061 WRREC LDX ZERO 041030

215 2064 WLOOP TD OUTPUT E

220 2067 JEQ WLOOP 302064

225 206A LDCH BUFFER,X 509039

230 206D WD OUTPUT DC

235 2070 TIX LENGTH 2C

240 2073 JLT WLOOP 382064

245 2076 RSUB 4C

250 2079 OUTPUT BYTE X’05’ 05

255 END FIRST

10) Write an Algorithm for pass 1 of SIC Assembler.

11) Write an algorithm for pass 2 of SIC assembler.

  1. What are the Data Structures used in an Assembler? Data Structures: Operation Code Table (OPTAB) Symbol Table (SYMTAB) Location Counter(LOCCTR)

  2. Explain the features of a Symbol Table.

  • SYMTAB (symbol table)
  • Content Label name and its value (address) May also include flag (type, length) etc.
  • Usage Pass 1 : labels are entered into SYMTAB with their address (from LOCCTR) as they are encountered in the source program Pass 2 : symbols used as operands are looked up in SYMTAB to obtain the address to be inserted in the assembled instruction
  • Characteristic Dynamic table (insert, delete, search)
  • Implementation Hash table for efficiency of insertion and retrieval

COPY 1000

FIRST 1000

CLOOP 1003

ENDFIL 1015

EOF 1024

THREE 102D

ZERO 1030

15)..h..i Larger memory allows us to load many programs. 15)..h..ii The object code is relative to zero because the load address is variable. 15)..h..iii Program must be relocated when it is loaded in memory. 15)..i (^) Register set mapping. 15)..i..i A separate register table can store the numeric values of the registers. 15)..i..ii The numeric values of the registers can be preloaded with the symbol table. 15)..j Relative (PC and base) addressing mode. 15)..j..i Operand value is subtracted from PC or base register value. 15)..j..ii PC relative addressing provides a displacement from – to +2047. 15)..j..iii Base relative addressing provides a displacement from 0 to

  1. What is Program Relocation? Program relocation
  • Principles.
    • The load address of an object program is unknown at assembly time if the system implements the multiprogramming feature.
    • The assembler generates addresses relative to zero in the object program.
    • At load time, relocation is performed by adding the load address to the relative addresses.
    • Operands of instructions that use direct addressing must be relocated, and the assembler provides the relocation information in the object program.
    • Operands of instructions that use relative addressing do not need to be relocated.
    • Relocation can be processed by the loader or by the CPU using relocation registers.
  1. (^) What are the advantages of program relocation? Program Relocation
  • The larger main memory of SIC/XE
  • Several programs can be loaded and run at the same time.
  • This kind of sharing of the machine between programs
  • is called multiprogramming
  • To take full advantage
  • Load programs into memory wherever there is room
  • Not specifying a fixed address at assembly time
  • Called program relocation
  1. (^) What are program blocks? Program Blocks
  • Refer to segments of code that are rearranged within a single object program unit
  • USE [blockname]
  • At the beginning, statements are assumed to be part of the unnamed (default) block
  • If no USE statements are included, the entire program belongs to this single block
  • Each program block may actually contain several separate segments of the source program
  1. How the program blocks are assembled? Program Blocks - Implementation
  • Pass 1
    • Each program block has a separate location counter
  • Each label is assigned an address that is relative to the start of the block that contains it
  • At the end of Pass 1, the latest value of the location counter for each block indicates the length of that block
    • The assembler can then assign to each block a starting address in the object program
  • Pass 2
    • The address of each symbol can be computed by adding the assigned block starting address and the relative address of the symbol to that block
  • Each source line is given a relative address assigned and a block number
  1. What is one pass assembler? Explain the functioning of one-pass assembler.
  • One-pass assemblers are used when
    • it is necessary or desirable to avoid a second pass over the source program
    • the external storage for the intermediate file between two passes is slow or is inconvenient to use
  • Main problem: forward references to both data and instructions
  • One simple way to eliminate this problem: require that all areas be defined before they are referenced. - (^) It is possible, although inconvenient, to do so for data items. - Forward jump to instruction items cannot be easily eliminated.

Sample Program for a One-Pass Assembler

Load-and-Go Assembler

  • Load-and-go assembler generates their object code in memory for immediate execution.
  • No object program is written out, no loader is needed.
  • It is useful in a system oriented toward program development and testing such that the efficiency of the assembly process is an important consideration.
  • the defining expression
  • the number of undefined symbols in the defining expression
  • the undefined symbol (marked with a flag *) associated with a list of symbols depend on this undefined symbol.
  • (^) When a symbol is defined, we can recursively evaluate the symbol expressions depending on the newly defined symbol.

two undefined symbol in the defining expression

2 MAXLEN EQU BUFEND-BUFFER

Forward Reference Example

Object Program from One-Pass Assembler

After scanning line 160

5 BUFEND EQU *

4 BUFFER RESB 4096

appended to the list

3 PREVBT EQU BUFFER-

depending list

depending list

undefined symbol

undefined symbol

defining expression

SYMTAB

SYMTAB

OPTAB

Source

program

Object

codes

Intermediate

file

Pass 2

Pass 1

Object Code in Memory and SYMTAB

Object Code in Memory and SYMTAB

After scanning line 40