Unit 1: Introduction To System Programming
Unit 1: Introduction To System Programming
Introduction to System
Programming
Contents
• System Software
• Machine Structure
• Machine language
• Assembly Language
• Assemblers
– Design of two pass assembler
System Software
• System Software vs Application
– Most system software are machine dependency.
– System programs are intended to support the
operation and use of the computer itself, rather
than any particular application.
• Examples of system software
– Text editor, assembler, compiler, loader or linker,
debugger, macro processors, operating system,
database management systems
System Software
• Text editors
• Loaders
• Pre Processors
• Assemblers
• Macro processors
• Compilers
• Debuggers
System Software Concept
Users
Application Program
Utility Program
Debugger Macro Processor Text Editor
(Library)
OS
Memory Process Device Information
Management Management Management Management
• Loaders
– Loads programs into memory and prepares them for execution
– Reads the contents of the executable file containing the program
instructions into memory
• Assemblers
– Converts Assembly Language code in to machine language
• Macro processors
– Carries out systematic set of replacements i.e. macro expansion
– Often included in other programs, like assemblers and compilers
System Software
• Compilers
– Translates a program written in HLL to executable machine language
– Prompts developer of errors
– object code is generated.
• Interpreter
– translates each instruction, executes it
– No object code is generated
• Debuggers
– test and debug a target program
• Linkers
– one or more objects generated by a compiler and combines them into
a single executable program
• Pre Processor
– processes our source code before compilation
Language Processors
Machine Structure
Machine Structure
• Memory address register (MAR): contains the address of the
memory location that is to read from or stored into.
• ADD 2,176
Machine Structure
• At first, the address from the IC is copied to the MAR.
• Then the instruction is fetched to the MBR.
• The instruction is then transferred to the IR.
• Then the operand of the instruction is checked and the
corresponding branch is taken, here ADD branch is chosen.
• Then the memory location of the second operand is placed
in the MAR.
• Then the content is placed in MBR.
• Now the first operand is placed in the WR.
• Finally the sum of WR and MBR is calculated and the stored
in WR.
• The content of WR is stored to the register that contained
first operand.
• And then IC is incremented to point to the next instruction.
Generations of Computer Languages:
Language Levels
High Level Language
Assembler Language
Machine Language
Micro - Firmware
programming
Hardware
High-level languages: Third Generation
• Machine code:
23
Statement format
An Assembly language statement has following
format:
[Label] <opcode> <operand spec>[,<operand spec>..]
If a label is specified in a statement, it is associated as a
symbolic name with the memory word generated for the
statement.
Use of Constants
• The DC statement does not really implement constants
• it just initializes memory words to given values.
• The values are not protected by the assembler and can
be changed by moving a new value into the memory
word.
• In the above example, the value of ONE can be changed
by executing an instruction
MOVEM BREG, ONE
Assembly Language Statements
Use of Constants
• An Assembly Program can use constants just like HLL, in
two ways – as immediate operands, and as literals.
Use of Constants
• 2) A literal is an operand with the syntax = '<value>'.
• It differs from a constant because its location cannot be
specified in the assembly program.
• Its value does not change during the execution of the
program.
• It differs from an immediate operand because no
architectural provision is needed to support its use.
• ORIGIN 321
• ORIGIN SYMBOL+5
ORIGIN
LN Code LC
1 … 201
.
5 ADD CREG, =‘1’ 205
6 ORIGIN 210
7 MULT DREG, =‘1’ 210
8 … 211
15 END
EQU
• <Symbol> EQU <address specification>
Symbol Address
N 103
• Since there the instructions take different
amount of memory, it is also stored in the
mnemonic table in the “length” field
Mnemonic Table
Symbol Address
Data Access
AGAIN 104
-- > Control Access
N 113
Symbol Table
Data structures
• Mnemonics table is a fixed table which is
merely accessed by the analysis and synthesis
phases
• Symbol table is constructed during analysis
and used during synthesis
Tasks Performed : Analysis Phase
• Isolate the labels, mnemonic, opcode and operand fields
of a statement.
START 100
MOVER BREG, N
MULT BREG, N
STOP
N DS 5
• Symbol Table:
– This is created during pass 1
– All the labels of the instructions are symbols
– Table has entry for symbol name, address value.
• Forward reference:
– Symbols that are defined in the later part of the
program are called forward referencing.
– There will not be any address value for such
symbols in the symbol table in pass 1.
Assembler: Design
Intermediate
Pass 1 Code Pass 2 Object
codes
OPTAB
SYMTAB
Mnemonic and
Label and address
opcode mappings
mappings created
are referenced
LITTAB
Variables / Constants
address mappings
created
Example
START 100
MOVER BREG, N
MULT BREG, N
ADD CREG, =‘3’
MOVEM AREG, M
ADD AREG,=‘6’
STOP
N DS 1
M DC ‘4’
END
OPTAB SYMTAB
MULT IS (03,1)
ADD IS (01,1)
MOVEM IS (05,1)
OPTAB N 110 1
START AD R#11
LITTAB
MOVER IS (04,1)
Literal Address
MULT IS (03,1)
ADD IS (01,1) =‘3’ 105
MOVEM IS (05,1) =‘4’ 106
LTORG AD R#12
=‘6’ 116
STOP IS (00,1)
DS DL R#7 Literal No
DC DL R#8
#1
END AD R#10
POOLTAB #3
Intermediate Code (IC) Format
• IC must contain following three fields:
– Address
– Representation of Mnemonic Opcode
– Representation of Operands
Declaration Statements
(DL)
DC 01
DS 02
AREG 01 LT 01
BREG 02 LE 02
CREG 03 EQ 03
DREG 04 GT 04
GE 05
ANY 06
• (Number)
Representation of Operands
• Operand 2 (S,C,L)
• (Operand Class, Code)
• S = Symbol Code = Entry in Symbol Table
• C = Constant Code = Constant Value
• L = Literal Code = Entry in Literal Table
Intermediate Code (IC) Format
START 200
READ A
LOOP MOVER AREG,A
.
.
SUB AREG,=‘9’
BC GT,LOOP
STOP
A DS 2
LTORG
.
Intermediate Code (IC) Format
• Variant I
(AD,01) (C,200)
(IS,09) (S,01)
(IS,04) (1) (S,01)
.
.
(IS,02) (1) (L,01)
(IS,07) (4) (S,02)
(IS,00)
(DL,02) (C,1)
(AD,05)
Variant I
Intermediate Code (IC) Format
• Variant II
(AD,01) (C,200)
(IS,09) A
(IS,04) AREG,A
.
.
(IS,02) AREG (L,01)
(IS,07) GT, LOOP
(IS,00)
(DL,02) (C,1)
(AD,05)
Variant II
Intermediate Code (IC) Format
• Variant I
– Complete processing of Operands is needed
– Reduces the work of pass II
• Variant II
– Operand processing has to be done in Pass II
– IC is less compact
– Transfers some coding load from Pass I to Pass II
Assembler Pass I
Step 1: Initialization
loc_cntr= 0 (default value)
pooltab_ptr= 1
POOLTAB[1] = 1
Littab_ptr=1
Step 2: While next statement is not an END
statement
a)If label is present then
this_label= symbol in label field
Enter ( this_label, loc_cntr) in SYMTAB
b)If an LTORG statement then
i) Process literals
make entry in literal table
ii) pootab_ptr= pootab_ptr++
iii) POOLTAB[pooltab_ptr] = littab_ptr
c) If START or ORIGIN statement then
loc_cntr= value specified in operand field
d) If an EQU statement then
this_addr= value of <addrspace>
correct the symtab_entry for
this_label to (this_label, this_addr)
e) If a declaration statement then
i) code = code of declaration statement
ii) size = size of memory area required by
DC/DS
iii) loc_cntr= loc_cntr+ size
iv) Generate IC ‘(DL, code)…’
f) If an imperative statement
i) code = machine opcode from OPTAB
ii) loc_cntr= loc_cntr+ instruction length from
OPTAB
iii) If operand is literal then
this_literal= literal in operand field
LITTAB[littab_ptr] = this_literal
littab_ptr= littab_ptr+ 1
Generate IC ‘ (IS,code)(L,this_literal)’
e) If an imperative statement
i.Get operand address from SYMTAB or LITTAB
ii.Assemble instruction in machine_code_buffer
iii.Size = size of instruction
f) If size is not equal to 0
i.move contents of machine_code_buffer
to the address code_area_address+ loc_cntr
ii.loc_cntr= loc_cntr+ size
DC SI (Storage Immediate)
DS RS (Register Storage)
LTORG
DROP
EQU
Donovan's Instruction Set
Types of Register Memory Requirement
RR 2 Bytes
RX 4 Bytes
RS 4 Bytes
SI 4 Bytes
SS 6 Bytes
• RR type instruction: Ending with R
– SR,BR,BALR,BCR,etc.
• SI type instruction: Ending with I
– LI,AI,CLI,etc.
• RX type instruction: Ending with other than R/I
– A,R,ST,S,etc.
Donovan's Instruction Set
Label Opcode Operand
DATA DC F’5’
Data Size
H (Half Word) 2 Byte
F (Full Word) 4 Byte
D (Double Word) 8 Byte
C (Character) 1 Byte
IBM 360/370 Instruction Set
IBM 360/370 Instruction Set
IBM 360/370 Instruction Set
Design Procedure of ALP
Alignment
DC / DS F multiple of 4
DC / DS H multiple of 2
DC / DS D multiple of 8
LTORG
If LTORG is encountered then 1st assign the value to of
literal.
See for (=F) literal in program while making literal table,
we have all instruction with F in front
e. g. = F ‘10’ 32
-> 1st literal should be always placed at double word
location i.e. multiple of 8.
Literal LC
= F ‘25’ 36
= F ‘ 4’ 40
LTORG
Literal Table
literal value R
= F ‘10’ 32 R
= F ‘25’ 36 R
Machine Code
– RR val1, val2 RR val1, val2
How to solve
OFFSET - value of (symbol/literal) – (B) /B- content
value of base table
BNE - Always changes into BC 7
BR 14 – Always changes into BCR 15, 14
DC - Corresponding Constant
DS- Blank