System Programming- Unit I

Saranya1702 4,642 views 72 slides May 27, 2021
Slide 1
Slide 1 of 72
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72

About This Presentation

System Programming for Bangalore University, BCA


Slide Content

SYSTEM PROGRAMMING (BCA 602T- VI sem ) 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 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

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

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….

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

(Debugger)

MACHINE STRUCTURE GENERAL HARDWARE ORGANIZATION OF COMPUTER SYSTEM

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..)

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

Assembler Loaders Macros Compilers Formal System Components of System Software

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

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

In a simple loading scheme, The assembler outputs the machine language translation of a program to secondary storage. Loader is placed in main memory. 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

The task of adjusting programs so that they may be placed in arbitrary memory locations is called Relocation . Relocation loaders perform four functions- Allocation allocate space in memory for the programs Linking resolve symbolic references between object programs Relocation adjust all address-dependent locations(address constants) to correspond to the allocated memory space. Loading physically place the machine instructions and data into memory. Loader(Contd..)

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.

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

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

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

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.)

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.)

Fig.: General Machine structure- IBM 360/370

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..)

LC

Memory Registers Data Instructions Special features(Interrupt System) General Approach to new machine

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- Address= Offset+ Base Register Contents + Index Register Contents Nibble 4

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

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.

DATA Data formats for the system 360/370

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

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

INSTRUCTION FORMAT Basic 360 instruction format

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

Consider that general register 5 contains the number 1000 c auses 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

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

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

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

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

Load-store Register Instructions LOAD GROUP STORE GROUP

Fixed Point Arithmetic Instructions ADD GROUP COMPARE GROUP DIVIDE GROUP MULTIPLY GROUP SUBTRACT GROUP

Logical instructions COMPARE GROUP MOVE GROUP AND GROUP OR GROUP XOR GROUP SHIFT GROUP

Transfer instructions LINKAGE GROUP BRANCH GROUP Miscellaneous instructions

The 360 has hardware protection in blocks of 2048 bytes and has an elaborate interrupt structure. Special Features

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

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..)

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

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

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

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..)

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..)

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 as the base Wastage of memory Need of relocation. Instruction would overlap data in the core. Long way, no looping(Contd..)

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

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

Address modification using instructions as data(Contd..)

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..)

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

SR 4, 4 Clear register 4 by subtracting the contents of register 4 from register 4. The contents of register 4=0

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..)

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..)

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

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..)

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..)

Final version of the program for additional assumptions

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

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..)

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

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..)

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..)

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

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..)

Assembly Language Program

REVISION