KEMBAR78
System Programming- Unit I | PPTX
Prepared by
Mrs. Saranya V, M.Sc., M.Phil.
Assistant Professor,
BCA Dept.,
TICM

 System Software
 Machine Structure
*Memory *Processor
 Evolution of components of a programming System
1. Assembler 2. Loaders 3.Macros
4. Compilers 5. Formal System
 General Machine structure
 CPU
 Memory
 I/O channels
 Machine Structure of IBM 360
1. Memory 2.Registers 3. Data 4. Instructions 5.Special Features
 Machine Language
1.Long way, no looping.2. Address modification using instruction as data.
3. Address modification using index registers. 4. Looping
 Assembly Language
1.Pseudo-OP 2. Machine-op
Content
2

 System Programming consists of a variety of programs
that support the operations of a computer.
 This software makes it possible for the user to focus on an
application or the other problem to be solved.
 System programs (e.g. compiler, loader macro processors,
and operating systems) were developed to make computer
better adapted to the need of their users.
System Programming
3

Types of Software
System Software
 Support operations on the
computer.
 Machine Dependent
 Programmer should know the
architecture of the system.
 Eg.: OS, Loaders, Linkers,
Assemblers…
Application Software
 Perform certain user specified
tasks.
 Machine Independent
 Programmer need not know
the architecture of the system.
 Eg.: Inventory, Payroll,
Banking….
4

 System software is a set of programs written for a
computer system to make the system better adapted
to the needs of the users.
 Eg: Text editors, Compilers, Loaders, Assemblers…
System Software
5

(Debugger)
6

MACHINE STRUCTURE
GENERAL HARDWARE ORGANIZATION OF COMPUTER SYSTEM
7

 Memory is a device where information are stored in the form of 0’s
& 1’s called bits.
 Bits are typically grouped in units – words, characters or bytes.
 Memory locations are specified by address.
 The contents of a memory word is coded into group of bits which
may be interpreted as data or instructions.
 A code is a set of rules for interpreting groups of bits.Eg. BCD-
decimal digits, ASCII/EBCDIC- characters, OP code- specific
processor operations.
MACHINE STRUCTURE(Contd..)
8

Processor is a device that operates on information.
 It performs a sequence of operations specified by instructions in memory.
 A program or a subprogram(procedure) is sequence of instructions.
MACHINE STRUCTURE(Contd..)
Processors
I/O processors CPUs
Data transfer b/w
memory & peripheral
devices
Manipulations of
data stored
in memory 9

 Assembler
 Loaders
 Macros
 Compilers
 Formal System
Components of System Software
10

 An assembler is a type of computer program that interprets software
programs written in assembly language(mnemonics) into machine
language, code and instructions that can be executed by a computer.
 An assembler enables software and application developers to access,
operate and manage a computer's hardware architecture and
components.
 An assembler is sometimes referred to as the compiler of assembly
language. It also provides the services of an interpreter.
Assembler
11

 A loader is a routine that loads an object program &
prepares it for execution.
 The loader includes schemes like Allocation,
Relocating & Direct linking.
 Since the loader program is much smaller than the
assembler, this makes more core memory available
to the user’s program.
Loader
12

 In a simple loading scheme,
1. The assembler outputs the machine language translation of a
program to secondary storage.
2. Loader is placed in main memory.
3. The loader places the machine language version of the user’s
program into memory and transfers control to it.
 A subroutine is a set of computer instructions that accomplish
a task and be used by other routines.
Open subroutine
(macro def.)
Closed subroutine
Loader(Contd..)
code is inserted to main program
i.e. if open subroutine is called 3times,then
It would appear in 3 different places in calling prog.
Stored outside the main routine & Control transfers
to the subroutine
13

 The task of adjusting programs so that they may be placed in
arbitrary memory locations is called Relocation.
 Relocation loaders perform four functions-
1. Allocation allocate space in memory for the programs
2. Linking resolve symbolic references between object programs
3. Relocation adjust all address-dependent locations(address
constants) to correspond to the allocated memory space.
4. Loading physically place the machine instructions and data into
memory.
Loader(Contd..)
14

Compiler
A compiler is a computer program (or a set of programs) that transforms
source code written in a programming language (the source language) into
another computer language (the target language), with the latter often
having a binary form known as object code.
COMPILER
 Converts high level lang. to
machine lang. as a whole
program.
 Compiled programs run
quickly
 Need not be recompiled to
re-run.
 In memory only during
compilation. During runtime
only machine code is resident in
memory
INTERPRETER
 Converts high level lang. to
machine lang. step by step.
 Interpreted programs run
slowly.
 To be interpreted all over
again to re-run.
 In memory only during
execution.
15

 A macro is a single line abbreviation for group of
statement.
 A macro processor is a program that substitutes and
specialized macro definitions for macro calls.
 A Macro consists of macro-definition, macro-
processor, macro-calls.
Macros
16

 A formal system consists of a language over some alphabet of
symbols together with (axioms and) inference rules that
distinguish some of the strings in the language as theorems.
 A formal system has the following components:
 A finite alphabet of symbols.
 A syntax that defines which strings of symbol are in the
language of our formal system.
 A decidable set of axioms and a finite set of rules from which
the set of theorems of the system is generated. The rules must
take a finite number of steps to apply.
Formal Systems
17

 All the conventional modern computers are based upon the
concept of stored program computer, the model that was proposed
by John von Neumann.
 The components of a general machine are as follows:
1. Instruction interpreter: A group of electronic circuits performs the
intent of instruction of fetched from memory.
2. Location counter: LC otherwise called as program counter PC or
instruction counter IC, is a hardware memory device which denotes
the location of the current instruction being executed.
MACHINE STRUCTURE
18

3. Instruction register: A copy of the content of the LC is stored in IR.
4. Working register: are the memory devices that serve as “scratch pad” for
the instruction interpreter.
5. General register: are used by programmers as storage locations and for
special functions.
6. Memory address registers (MAR): contains the address of the memory
location that is to read from or stored into.
Machine structure(Contd.)
19

7. Memory buffer register (MBR): contain a copy of the content of the
memory location whose address is stored in MAR. The primary interface
between the memory and the CPU is through memory buffer register.
8. Memory controller: is a hardware device whose work is to transfer the
content of the MBR to the core memory location whose address is stored
in MAR.
9. I/O channels: may be thought of as separate computers which interpret
special instructions for inputting and outputting information from the
memory.
Machine structure(Contd.)
20

Fig.: General Machine structure- IBM 360/370
21

 The basic instruction format is
 To illustrate how these components of the machine
structure interact let us consider an ADD instruction
ADD 2,176
where ADD is the operation code,
2 is the register number and
176 is the memory location
Machine Structure(Contd..)
22
LC
23

 Memory
 Registers
 Data
 Instructions
 Special features(Interrupt System)
General Approach to new machine
24
Memory
Various units of memory in hypothetical computer
 The addressing on the machine 360 is upto 2pow(24)
 The addressing on the 360 memory consists of three
components-
Nibble 4
25

 General purpose Registers- 16 – each 32 bits(R0 to R15)
 Floating point Registers - 4 -each 64 bits
 Program Status Word - 1 - each 64 bits
 PSW=value of location Counter, Protection Information &
Interrupt status.
Eg: ADD 1,901(2,15)
 Such complexity in addressing is required because, with the
base register, relocation of program is easy by just changing
the base register value. This promotes efficient addressing of
the core memory.
Registers
offset
Base register
index register
26

Register(Contd..)
 Without the use of base register, to address all possible
locations, we require 24 bits.
 But, if a base register is used, it requires only 32 bits.
 Advantages:
 Relocation of a whole program
 Efficient addressing of the core
 Saves 8 bits per address reference.
 Disadvantage:
 This 12 bits offset can specify numbers only from 0 to 4095.
 Address formation during execution has associated overheads. 27

DATA
Data formats for the system 360/370
28

 A program is a set of instructions.
 An instruction is a single operation of a process or defined by
an instruction set. Instructions may be of following types
 Arithmetic instructions
 Logical instructions
 Control or transfer instructions
 Special interrupt instructions
 An instruction includes an
opcode- specifying the operation to be performed
zero/ more operands- specify registers, memory location or literal data
INSTRUCTIONS
29

 Register operands refer to the data stored in one of the 16
general registers(32b long), which are addressed by 4-b
field in the instruction.
 Storage operands refer to data stored in core memory.
The length of the operand depends on the data-type.
 Immediate operand is a single byte of data and is stored
as part of the instructions.
INSTRUCTION FORMAT
30

INSTRUCTION FORMAT
Basic 360 instruction format
31

 RR instruction denotes register to register operation.
i.e, both the operands are register.
 The length of RR instruction is 2 bytes (16 bits)
 Example: the instruction is Add 3, 4
Instructions(Contd..)-RR format
32

 Consider that general register 5 contains the number 1000
causes the contents of the word(32 b) located at address
=c(5)+c(0)+16
=1000+0+16
=1016 to be added to the contents of general
register 3.
Instructions(Contd..)-RX format
33

 In SS instructions, the length is always one less than the data
moved.
 The instruction involve two storage operands.
Storage operand1 address=c(B1)+D1=c(5)+32=1000+32=1032
Storage operand2 address=c(B2)+D1=c(5)+300=1000+300=1300
 This instruction moves(copies) the 80 bytes from locations 1032 to
1300
Instructions(Contd..)-SS format
34

 Immediate operands are a single byte of data and are stored
as part of the instruction.
 Again assuming register 5 to contain 1000, the above SI
instruction, causes the byte 0100 0000 to be stored at location
1004 [c(B1)+D1= 1000+4= 1004]
Instructions(Contd..)-SI format
35

Instruction Type Length(in Bytes) Address of Storage Operand
RR 2 -
RX 4 C(B2)+C(X2)+D2
RS 4 C(B2)+D2
SI 4 C(B1)+D1
SS 6 C(B1)+D1 & C(B2)+D2
Summary of instruction format
36

 A subset of 360/370 instructions are
 Load-store register instructions
 Fixed point arithmetic instructions
 Logical instructions
 Transfer instructions
 Miscellaneous instructions
360/370 Instruction Set
37
Load-store Register Instructions
LOAD
GROUP
STORE
GROUP
38
Fixed Point Arithmetic Instructions
ADD GROUP
COMPARE GROUP
DIVIDE GROUP
MULTIPLY GROUP
SUBTRACT
GROUP
39
Logical instructions
COMPARE
GROUP
MOVE GROUP
AND GROUP
OR GROUP
XOR GROUP
SHIFT GROUP
40
Transfer instructions
LINKAGE
GROUP
BRANCH
GROUP
Miscellaneous instructions
41

 The 360 has hardware protection in blocks of 2048
bytes and has an elaborate interrupt structure.
Special Features
42

 Computer understands 0’s & 1’s which is called as
machine language.
 It is a system of instructions and data executed
directly by a computer’s CPU.
MACHINE LANGUAGE
43

 Advantages:
 Instructions of a machine language program are immediately
executed, they require no compilation or translation.
 Machine language make efficient use of storage
 Disadvantages:
 Machine languages are machine dependent
 Machine language is difficult to program, since the
programmers has to know the architecture of the system.
 Writing, reading, correcting or modifying a machine
language program is difficult.
MACHINE LANGUAGE(contd..)
44

 Write a program that will add
the number 49 to the contents
of 10 adjacent full words
(32bits or 4 bytes) in memory
with the following
assumptions:
1. The 10 numbers are contiguous
full words beginning at absolute
location 952.
2. The program is in core memory
starting at absolute location 48.
3. The number 49 is a full word at
absolute location 948.
4. Register 1 contains a 48.
Example program
45

MACHINE LANGUAGE(contd..)
 This program can be written using following
different ways
1. Long way, no looping.
2. Address modification using instruction as data.
3. Address modification using index registers.
4. Looping
46

 Register 2 is used as an
accumulator
 Index register is
0.therefore the contents of
the index register is also
0.
 Address of the storage
operand=offset + contents
of the base register.
 Content of register 1 is 48.
Long way, no looping
47

L 2,904(0, 1)
• Load the first number into register 2
• Address of the storage operand=904+contents of base register1
=904+48
=952
• Contents of register 2=contents of memory location 952=Data1
A 2,900(0, 1)
• Add 49 with data1
• Address of the storage operand =900+contents of base register1
=900+48
=948
• Contents of register 2 =contents of register2+contents of memory
location 948
=Data1+49
Long way, no looping(Contd..)
48

ST 2,904(0, 1)
Address of storage operand =904+contenet of register1
=904+48
=952
Content of register 2 =content of base register2
=Data1+49
L and ST are RX type instruction. Whose size is 4 bytes.
Therefore absolute and relative address is incremented by 4.
Long way, no looping(Contd..)
49

 Advantages
• Implementation is easy.
 Disadvantages
• Instructions are repeated for all the data items
• It is impossible to access both the first data item and the
last data item using register 1 asthe base
• Wastage of memory
• Need of relocation.
• Instruction would overlap data in the core.
Long way, no looping(Contd..)
50

 In this approach the problem consisting only of those
3 instructions followed by a sequence of commands
that would change the offset of the load and store
instruction by adding 4 to them
 In addition to the 4 assumptions given in the
problem statement, we are going to make one more
assumptions.
 Assumption 5: relative location 896 contains a 4.
 Here instruction is treated as data. Therefore adding
4 to an instruction will update its offset.
Address modification using
instructions as data
51

Address modification using
instructions as data(Contd..)
• For example, if location 48 contains the instruction L 2,904(0, 1)
• The instruction is stored as follows from byte number 48
• Now when we add 4 to this instruction, the offset present in the 4th
byte is treated as data and is incremented by 4.
L+4=904+4
=908
52
Address modification using instructions as data(Contd..)
53

 Advantages
• Saves memory
• Address is modified easily using the instruction.
 Disadvantages
• Treating instructions as data is not a good programming
practice
• Separate instructions are used for increasing the
displacement(offset) of load and store
Address modification using
instructions as data(Contd..)
54

 In this approach,we use the same 3 instructions
i.e.,load,add and store.we simply loop through these
3 instructions,updating the storage operands of load
and store instructions,by adding 4 to the contents of
the index register during each pass.
 Register 4 is used as an index register.
Address modification using
index registers
55

SR 4, 4
• Clear register 4 by subtracting the contents of
register 4 from register 4.
• The contents of register 4=0 56

L 2,904(4,1)
• Load data element of array
• Address of the storage operand =904+contents of index register
4+contents of base
register 1
=904+0+48
=952
• Content of register 2 =contents of memory location 952=data1.
A 2,900(0, 1)
• Add 49
• Address of the storage operand =900+contents of base register 1
=900+48
=948
• Contents of register 2 =contents of register 2+contents of memory
=Data1+49
Address modification using
index registers(Contd..)
57

ST 2,904(4, 1)
• Replace data element
• Address of the storage operand =904+contents of index register 4+contents of
base register1
=904+0+48
=952
• Contents of memory location 952 =contents of register2
=Data1+49
A 4,896(0,1)
• Add 4 to index register
• Address of the storage operand =896+contents of base register1
=896+48
=944
• Contents of index register 4 = Contents of index register 4+contents of memory
location944
=0+4 =4
Address modification using
index registers(Contd..)
58

• The additional assumptions made for this method
are
• Assumption 6: relative location 892 contains a 10
• Assumption 7: relative location 888 contains a 1.
Looping
59

60

L 3,892(0, 1)
 Load data into register 3
 Address of the storage operand =892+C(B1)
=892+48
=940.
 Content of register 3 =contents of memory location 940
=10
S 3,888(0, 1)
 Subtract 1
 Address of the storage operand =888+contents of register 1
=888+48
=936
 C(R3) =C(R3)-contents of memory location936
=10-1
=9
ST 3,892(0, 1)
 Store temp
 Address of the storage operand =892+C(R1)
=892+48
=940
 Content of memory location 940 =contents of register 3
=9
Looping(Contd..)
61

BC 2, 2(0,1)
 Branch if result is positive.
 2 denotes a condition code
 Address of the storage operand =2+C(B1)
=2+48
=50
Looping(Contd..)
62

 Final version of the program for additional assumptions
63

 Assembly language is a low level programming
language that allows and uses to write programs
using mnemonics (symbols)
 Features:
 Mnemonic operation codes
 Symbolic operands
 Data declarations
ASSEMBLY LANGUAGE
64

 Advantages
1. It is mnemonic
2. Reading is easier
3. Addresses are symbolic
4. Introduction of data to program is easier
5. It can be easily modified than machine language programs.
 Disadvantages
1. An assembly language is required to translate source program into object
program
2. It is machine dependent.
3. Lack of portability of programs between computers of different makes.
ASSEMBLY LANGUAGE(Contd..)
65

 Pseudo opcode is an assembly language instruction that specifies
an operation of the assembler.
 USING
Using is a pseudo opcode that indicates to the assembler which General
Purpose Register to use as a base register and what value it contained at
execution time
Syntax USING <content of base register><GPR to be used as base
register>
Ex: USING * 5
 START
Start is a pseudo opcode that tells the assembler where the beginning of
the program is and allows the user to give a name to the program
Ex: START sum Or sum START
PSEUDO-OP
66

 END:
End is a pseudo opcode that tells the assembler that the last
statement of the program has been reached
Ex: END
 EQU:
EQU is the pseudo opcode which allows the program to define
variables
Ex: BASE EQU 15
 DROP:
Drop is a pseudo opcode which indicates an unavailable base
register and its contents
Syntax: DROP<BS register number>
Ex: DROP 15
PSEUDO-OP(CONTD..)
67

 DC (data constant)/(define constant):
DC is a declarative pseudo opcode used to create a memory area to hold
a constant value
Syntax: <Label>DC ‘constants’
Ex: FOUR DC ’F4’
 DS (data storage)
DS is the pseudo opcode that reserves storage for the data and gives
them a name
Syntax <Label> DS ‘size’
Ex: FOUR DS ‘1F’
 LTORG:
LTORG is a pseudo opcode which tells the assembler to place the
encountered literals at an earlier location
PSEUDO-OP(CONTD..)
68

 Machine- OP represents a machine instruction to the
assembler.
 Machine ins should be included in the program to load
the proper value into the base register at execution time.
 BALR:
• BALR is a branch and link instruction. It is an instruction
to the computer to load a register with the next address
and branch to the address specified in the second field.
• BALR loads the base register and it is an executable
statement it is an RR type instruction whose length is 2
bytes.
Ex: BALR 15,0
MACHINE OPCODES
69

 BR:
BR is a machine opcode indicating branch to the location
whose address is in general register
Ex: BR 14
 BCT:
• BCT indicates branch and count it is a RX type
instruction whose size is 4 bytes.
Ex: BCT 3, loop
• Decrements register 3 by 1 if result is not 0 branch
back to loop
MACHINE OPCODES(Contd..)
70

Assembly Language Program
71
System Programming- Unit I

System Programming- Unit I

  • 1.
    Prepared by Mrs. SaranyaV, M.Sc., M.Phil. Assistant Professor, BCA Dept., TICM
  • 2.
      System Software Machine Structure *Memory *Processor  Evolution of components of a programming System 1. Assembler 2. Loaders 3.Macros 4. Compilers 5. Formal System  General Machine structure  CPU  Memory  I/O channels  Machine Structure of IBM 360 1. Memory 2.Registers 3. Data 4. Instructions 5.Special Features  Machine Language 1.Long way, no looping.2. Address modification using instruction as data. 3. Address modification using index registers. 4. Looping  Assembly Language 1.Pseudo-OP 2. Machine-op Content 2
  • 3.
      System Programmingconsists of a variety of programs that support the operations of a computer.  This software makes it possible for the user to focus on an application or the other problem to be solved.  System programs (e.g. compiler, loader macro processors, and operating systems) were developed to make computer better adapted to the need of their users. System Programming 3
  • 4.
     Types of Software SystemSoftware  Support operations on the computer.  Machine Dependent  Programmer should know the architecture of the system.  Eg.: OS, Loaders, Linkers, Assemblers… Application Software  Perform certain user specified tasks.  Machine Independent  Programmer need not know the architecture of the system.  Eg.: Inventory, Payroll, Banking…. 4
  • 5.
      System softwareis a set of programs written for a computer system to make the system better adapted to the needs of the users.  Eg: Text editors, Compilers, Loaders, Assemblers… System Software 5
  • 6.
  • 7.
     MACHINE STRUCTURE GENERAL HARDWAREORGANIZATION OF COMPUTER SYSTEM 7
  • 8.
      Memory isa device where information are stored in the form of 0’s & 1’s called bits.  Bits are typically grouped in units – words, characters or bytes.  Memory locations are specified by address.  The contents of a memory word is coded into group of bits which may be interpreted as data or instructions.  A code is a set of rules for interpreting groups of bits.Eg. BCD- decimal digits, ASCII/EBCDIC- characters, OP code- specific processor operations. MACHINE STRUCTURE(Contd..) 8
  • 9.
     Processor is adevice that operates on information.  It performs a sequence of operations specified by instructions in memory.  A program or a subprogram(procedure) is sequence of instructions. MACHINE STRUCTURE(Contd..) Processors I/O processors CPUs Data transfer b/w memory & peripheral devices Manipulations of data stored in memory 9
  • 10.
      Assembler  Loaders Macros  Compilers  Formal System Components of System Software 10
  • 11.
      An assembleris a type of computer program that interprets software programs written in assembly language(mnemonics) into machine language, code and instructions that can be executed by a computer.  An assembler enables software and application developers to access, operate and manage a computer's hardware architecture and components.  An assembler is sometimes referred to as the compiler of assembly language. It also provides the services of an interpreter. Assembler 11
  • 12.
      A loaderis a routine that loads an object program & prepares it for execution.  The loader includes schemes like Allocation, Relocating & Direct linking.  Since the loader program is much smaller than the assembler, this makes more core memory available to the user’s program. Loader 12
  • 13.
      In asimple loading scheme, 1. The assembler outputs the machine language translation of a program to secondary storage. 2. Loader is placed in main memory. 3. The loader places the machine language version of the user’s program into memory and transfers control to it.  A subroutine is a set of computer instructions that accomplish a task and be used by other routines. Open subroutine (macro def.) Closed subroutine Loader(Contd..) code is inserted to main program i.e. if open subroutine is called 3times,then It would appear in 3 different places in calling prog. Stored outside the main routine & Control transfers to the subroutine 13
  • 14.
      The taskof adjusting programs so that they may be placed in arbitrary memory locations is called Relocation.  Relocation loaders perform four functions- 1. Allocation allocate space in memory for the programs 2. Linking resolve symbolic references between object programs 3. Relocation adjust all address-dependent locations(address constants) to correspond to the allocated memory space. 4. Loading physically place the machine instructions and data into memory. Loader(Contd..) 14
  • 15.
     Compiler A compiler isa computer program (or a set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language), with the latter often having a binary form known as object code. COMPILER  Converts high level lang. to machine lang. as a whole program.  Compiled programs run quickly  Need not be recompiled to re-run.  In memory only during compilation. During runtime only machine code is resident in memory INTERPRETER  Converts high level lang. to machine lang. step by step.  Interpreted programs run slowly.  To be interpreted all over again to re-run.  In memory only during execution. 15
  • 16.
      A macrois a single line abbreviation for group of statement.  A macro processor is a program that substitutes and specialized macro definitions for macro calls.  A Macro consists of macro-definition, macro- processor, macro-calls. Macros 16
  • 17.
      A formalsystem consists of a language over some alphabet of symbols together with (axioms and) inference rules that distinguish some of the strings in the language as theorems.  A formal system has the following components:  A finite alphabet of symbols.  A syntax that defines which strings of symbol are in the language of our formal system.  A decidable set of axioms and a finite set of rules from which the set of theorems of the system is generated. The rules must take a finite number of steps to apply. Formal Systems 17
  • 18.
      All theconventional modern computers are based upon the concept of stored program computer, the model that was proposed by John von Neumann.  The components of a general machine are as follows: 1. Instruction interpreter: A group of electronic circuits performs the intent of instruction of fetched from memory. 2. Location counter: LC otherwise called as program counter PC or instruction counter IC, is a hardware memory device which denotes the location of the current instruction being executed. MACHINE STRUCTURE 18
  • 19.
     3. Instruction register:A copy of the content of the LC is stored in IR. 4. Working register: are the memory devices that serve as “scratch pad” for the instruction interpreter. 5. General register: are used by programmers as storage locations and for special functions. 6. Memory address registers (MAR): contains the address of the memory location that is to read from or stored into. Machine structure(Contd.) 19
  • 20.
     7. Memory bufferregister (MBR): contain a copy of the content of the memory location whose address is stored in MAR. The primary interface between the memory and the CPU is through memory buffer register. 8. Memory controller: is a hardware device whose work is to transfer the content of the MBR to the core memory location whose address is stored in MAR. 9. I/O channels: may be thought of as separate computers which interpret special instructions for inputting and outputting information from the memory. Machine structure(Contd.) 20
  • 21.
     Fig.: General Machinestructure- IBM 360/370 21
  • 22.
      The basicinstruction format is  To illustrate how these components of the machine structure interact let us consider an ADD instruction ADD 2,176 where ADD is the operation code, 2 is the register number and 176 is the memory location Machine Structure(Contd..) 22
  • 23.
  • 24.
      Memory  Registers Data  Instructions  Special features(Interrupt System) General Approach to new machine 24
  • 25.
    Memory Various units ofmemory in hypothetical computer  The addressing on the machine 360 is upto 2pow(24)  The addressing on the 360 memory consists of three components- Nibble 4 25
  • 26.
      General purposeRegisters- 16 – each 32 bits(R0 to R15)  Floating point Registers - 4 -each 64 bits  Program Status Word - 1 - each 64 bits  PSW=value of location Counter, Protection Information & Interrupt status. Eg: ADD 1,901(2,15)  Such complexity in addressing is required because, with the base register, relocation of program is easy by just changing the base register value. This promotes efficient addressing of the core memory. Registers offset Base register index register 26
  • 27.
     Register(Contd..)  Without theuse of base register, to address all possible locations, we require 24 bits.  But, if a base register is used, it requires only 32 bits.  Advantages:  Relocation of a whole program  Efficient addressing of the core  Saves 8 bits per address reference.  Disadvantage:  This 12 bits offset can specify numbers only from 0 to 4095.  Address formation during execution has associated overheads. 27
  • 28.
     DATA Data formats forthe system 360/370 28
  • 29.
      A programis a set of instructions.  An instruction is a single operation of a process or defined by an instruction set. Instructions may be of following types  Arithmetic instructions  Logical instructions  Control or transfer instructions  Special interrupt instructions  An instruction includes an opcode- specifying the operation to be performed zero/ more operands- specify registers, memory location or literal data INSTRUCTIONS 29
  • 30.
      Register operandsrefer to the data stored in one of the 16 general registers(32b long), which are addressed by 4-b field in the instruction.  Storage operands refer to data stored in core memory. The length of the operand depends on the data-type.  Immediate operand is a single byte of data and is stored as part of the instructions. INSTRUCTION FORMAT 30
  • 31.
     INSTRUCTION FORMAT Basic 360instruction format 31
  • 32.
      RR instructiondenotes register to register operation. i.e, both the operands are register.  The length of RR instruction is 2 bytes (16 bits)  Example: the instruction is Add 3, 4 Instructions(Contd..)-RR format 32
  • 33.
      Consider thatgeneral register 5 contains the number 1000 causes the contents of the word(32 b) located at address =c(5)+c(0)+16 =1000+0+16 =1016 to be added to the contents of general register 3. Instructions(Contd..)-RX format 33
  • 34.
      In SSinstructions, the length is always one less than the data moved.  The instruction involve two storage operands. Storage operand1 address=c(B1)+D1=c(5)+32=1000+32=1032 Storage operand2 address=c(B2)+D1=c(5)+300=1000+300=1300  This instruction moves(copies) the 80 bytes from locations 1032 to 1300 Instructions(Contd..)-SS format 34
  • 35.
      Immediate operandsare a single byte of data and are stored as part of the instruction.  Again assuming register 5 to contain 1000, the above SI instruction, causes the byte 0100 0000 to be stored at location 1004 [c(B1)+D1= 1000+4= 1004] Instructions(Contd..)-SI format 35
  • 36.
     Instruction Type Length(inBytes) Address of Storage Operand RR 2 - RX 4 C(B2)+C(X2)+D2 RS 4 C(B2)+D2 SI 4 C(B1)+D1 SS 6 C(B1)+D1 & C(B2)+D2 Summary of instruction format 36
  • 37.
      A subsetof 360/370 instructions are  Load-store register instructions  Fixed point arithmetic instructions  Logical instructions  Transfer instructions  Miscellaneous instructions 360/370 Instruction Set 37
  • 38.
  • 39.
    Fixed Point ArithmeticInstructions ADD GROUP COMPARE GROUP DIVIDE GROUP MULTIPLY GROUP SUBTRACT GROUP 39
  • 40.
    Logical instructions COMPARE GROUP MOVE GROUP ANDGROUP OR GROUP XOR GROUP SHIFT GROUP 40
  • 41.
  • 42.
      The 360has hardware protection in blocks of 2048 bytes and has an elaborate interrupt structure. Special Features 42
  • 43.
      Computer understands0’s & 1’s which is called as machine language.  It is a system of instructions and data executed directly by a computer’s CPU. MACHINE LANGUAGE 43
  • 44.
      Advantages:  Instructionsof a machine language program are immediately executed, they require no compilation or translation.  Machine language make efficient use of storage  Disadvantages:  Machine languages are machine dependent  Machine language is difficult to program, since the programmers has to know the architecture of the system.  Writing, reading, correcting or modifying a machine language program is difficult. MACHINE LANGUAGE(contd..) 44
  • 45.
      Write aprogram that will add the number 49 to the contents of 10 adjacent full words (32bits or 4 bytes) in memory with the following assumptions: 1. The 10 numbers are contiguous full words beginning at absolute location 952. 2. The program is in core memory starting at absolute location 48. 3. The number 49 is a full word at absolute location 948. 4. Register 1 contains a 48. Example program 45
  • 46.
     MACHINE LANGUAGE(contd..)  Thisprogram can be written using following different ways 1. Long way, no looping. 2. Address modification using instruction as data. 3. Address modification using index registers. 4. Looping 46
  • 47.
      Register 2is used as an accumulator  Index register is 0.therefore the contents of the index register is also 0.  Address of the storage operand=offset + contents of the base register.  Content of register 1 is 48. Long way, no looping 47
  • 48.
     L 2,904(0, 1) •Load the first number into register 2 • Address of the storage operand=904+contents of base register1 =904+48 =952 • Contents of register 2=contents of memory location 952=Data1 A 2,900(0, 1) • Add 49 with data1 • Address of the storage operand =900+contents of base register1 =900+48 =948 • Contents of register 2 =contents of register2+contents of memory location 948 =Data1+49 Long way, no looping(Contd..) 48
  • 49.
     ST 2,904(0, 1) Addressof storage operand =904+contenet of register1 =904+48 =952 Content of register 2 =content of base register2 =Data1+49 L and ST are RX type instruction. Whose size is 4 bytes. Therefore absolute and relative address is incremented by 4. Long way, no looping(Contd..) 49
  • 50.
      Advantages • Implementationis easy.  Disadvantages • Instructions are repeated for all the data items • It is impossible to access both the first data item and the last data item using register 1 asthe base • Wastage of memory • Need of relocation. • Instruction would overlap data in the core. Long way, no looping(Contd..) 50
  • 51.
      In thisapproach the problem consisting only of those 3 instructions followed by a sequence of commands that would change the offset of the load and store instruction by adding 4 to them  In addition to the 4 assumptions given in the problem statement, we are going to make one more assumptions.  Assumption 5: relative location 896 contains a 4.  Here instruction is treated as data. Therefore adding 4 to an instruction will update its offset. Address modification using instructions as data 51
  • 52.
     Address modification using instructionsas data(Contd..) • For example, if location 48 contains the instruction L 2,904(0, 1) • The instruction is stored as follows from byte number 48 • Now when we add 4 to this instruction, the offset present in the 4th byte is treated as data and is incremented by 4. L+4=904+4 =908 52
  • 53.
    Address modification usinginstructions as data(Contd..) 53
  • 54.
      Advantages • Savesmemory • Address is modified easily using the instruction.  Disadvantages • Treating instructions as data is not a good programming practice • Separate instructions are used for increasing the displacement(offset) of load and store Address modification using instructions as data(Contd..) 54
  • 55.
      In thisapproach,we use the same 3 instructions i.e.,load,add and store.we simply loop through these 3 instructions,updating the storage operands of load and store instructions,by adding 4 to the contents of the index register during each pass.  Register 4 is used as an index register. Address modification using index registers 55
  • 56.
     SR 4, 4 •Clear register 4 by subtracting the contents of register 4 from register 4. • The contents of register 4=0 56
  • 57.
     L 2,904(4,1) • Loaddata element of array • Address of the storage operand =904+contents of index register 4+contents of base register 1 =904+0+48 =952 • Content of register 2 =contents of memory location 952=data1. A 2,900(0, 1) • Add 49 • Address of the storage operand =900+contents of base register 1 =900+48 =948 • Contents of register 2 =contents of register 2+contents of memory =Data1+49 Address modification using index registers(Contd..) 57
  • 58.
     ST 2,904(4, 1) •Replace data element • Address of the storage operand =904+contents of index register 4+contents of base register1 =904+0+48 =952 • Contents of memory location 952 =contents of register2 =Data1+49 A 4,896(0,1) • Add 4 to index register • Address of the storage operand =896+contents of base register1 =896+48 =944 • Contents of index register 4 = Contents of index register 4+contents of memory location944 =0+4 =4 Address modification using index registers(Contd..) 58
  • 59.
     • The additionalassumptions made for this method are • Assumption 6: relative location 892 contains a 10 • Assumption 7: relative location 888 contains a 1. Looping 59
  • 60.
  • 61.
     L 3,892(0, 1) Load data into register 3  Address of the storage operand =892+C(B1) =892+48 =940.  Content of register 3 =contents of memory location 940 =10 S 3,888(0, 1)  Subtract 1  Address of the storage operand =888+contents of register 1 =888+48 =936  C(R3) =C(R3)-contents of memory location936 =10-1 =9 ST 3,892(0, 1)  Store temp  Address of the storage operand =892+C(R1) =892+48 =940  Content of memory location 940 =contents of register 3 =9 Looping(Contd..) 61
  • 62.
     BC 2, 2(0,1) Branch if result is positive.  2 denotes a condition code  Address of the storage operand =2+C(B1) =2+48 =50 Looping(Contd..) 62
  • 63.
      Final versionof the program for additional assumptions 63
  • 64.
      Assembly languageis a low level programming language that allows and uses to write programs using mnemonics (symbols)  Features:  Mnemonic operation codes  Symbolic operands  Data declarations ASSEMBLY LANGUAGE 64
  • 65.
      Advantages 1. Itis mnemonic 2. Reading is easier 3. Addresses are symbolic 4. Introduction of data to program is easier 5. It can be easily modified than machine language programs.  Disadvantages 1. An assembly language is required to translate source program into object program 2. It is machine dependent. 3. Lack of portability of programs between computers of different makes. ASSEMBLY LANGUAGE(Contd..) 65
  • 66.
      Pseudo opcodeis an assembly language instruction that specifies an operation of the assembler.  USING Using is a pseudo opcode that indicates to the assembler which General Purpose Register to use as a base register and what value it contained at execution time Syntax USING <content of base register><GPR to be used as base register> Ex: USING * 5  START Start is a pseudo opcode that tells the assembler where the beginning of the program is and allows the user to give a name to the program Ex: START sum Or sum START PSEUDO-OP 66
  • 67.
      END: End isa pseudo opcode that tells the assembler that the last statement of the program has been reached Ex: END  EQU: EQU is the pseudo opcode which allows the program to define variables Ex: BASE EQU 15  DROP: Drop is a pseudo opcode which indicates an unavailable base register and its contents Syntax: DROP<BS register number> Ex: DROP 15 PSEUDO-OP(CONTD..) 67
  • 68.
      DC (dataconstant)/(define constant): DC is a declarative pseudo opcode used to create a memory area to hold a constant value Syntax: <Label>DC ‘constants’ Ex: FOUR DC ’F4’  DS (data storage) DS is the pseudo opcode that reserves storage for the data and gives them a name Syntax <Label> DS ‘size’ Ex: FOUR DS ‘1F’  LTORG: LTORG is a pseudo opcode which tells the assembler to place the encountered literals at an earlier location PSEUDO-OP(CONTD..) 68
  • 69.
      Machine- OPrepresents a machine instruction to the assembler.  Machine ins should be included in the program to load the proper value into the base register at execution time.  BALR: • BALR is a branch and link instruction. It is an instruction to the computer to load a register with the next address and branch to the address specified in the second field. • BALR loads the base register and it is an executable statement it is an RR type instruction whose length is 2 bytes. Ex: BALR 15,0 MACHINE OPCODES 69
  • 70.
      BR: BR isa machine opcode indicating branch to the location whose address is in general register Ex: BR 14  BCT: • BCT indicates branch and count it is a RX type instruction whose size is 4 bytes. Ex: BCT 3, loop • Decrements register 3 by 1 if result is not 0 branch back to loop MACHINE OPCODES(Contd..) 70
  • 71.