Вы находитесь на странице: 1из 46

System Programming

Chapter 1
Introduction

1
Introdution

 System software consist of variety of programs that


support the operation of the computer.
 This software makes it possible for the user to focus
on an application or other problems to be solved,
without needing to know the detail how the machine
work internally.
 System Software consists of a variety of programs
that support the operation of a computer. „
 The software makes it possible for the users to focus
on an application or other problem to be solved,
without needing to know the details of how the
machine works internally. 2
Types of Software

 Application Software
» A set of programs written in a specific any programming
language to solve a particular problem.
» It is independent of the machine on which it is operated.
» Concerned mainly with the solution of the problem and
makes use of the computer software as a tool.
» Purpose of supporting or improving the user’s work with a
software.
» The focus is on the application.

3
Types…

 Example
» Word processing
– MS word, WordPad
» Database
– Oracle, MS Access
» Spreadsheet
– Excel, Apple Numbers
» Multimedia
– Real Player, Media Player
» Presentation Graphics
– MS PowerPoint

4
Types…

 System Software
» A set of programs that creates the environment to facilitate
working of an application software.
» Consists of a variety of programs that support the operation
of a computer.
» One characteristic in which most system software differ from
application software is machine dependency.
» Acts as an intermediary between computer hardware and
application programs.
» Controls the computer system and enhances its
performance.
» Focus is on the system.

5
Types…

 Example:
» In programming courses
– text editor, compiler, loader or linker, debugger, macro
processor
» In assembly language
– assembler
» All of these processes are controlled by interacting
with the operation system.

6
Examples of System Software

 Text Editor
» Allows user to create/modify a file having only
plain text.
» Edit contents to get an immediate visual feedback
– Emacs (Unix)
– Notepad (Microsoft)
– SimpleText, TextEdit (Mac OS)

7
Examples…

 Compiler
» Translates high level language to machine
language.
» Source code into data, that computer can
understand.
» Source code to object code
– ADA, BASIC, Fortran, Pascal
– C, C++, C#
– Open Source

8
Examples…

 Linker
» Object code from compiler is turned into executable program
» Gathers 1 or more objects generated by the compiler &
combines into a single EXE
» In IBM OS/360 termed as linkage editor

 Loader
» Loads programs from executables into memory and executes 9
Examples…

 Debugger
» Tests & debugs errors
» Code run on Instruction Set Simulator (ISS)
– Step by step
– Breakpoint
 DEBUG – Microsoft DOS built-in debugger
 Nemiver – Graphical C/C++ debugger
 Ups – Fortran, C
 VB Watch – Visual Basic
 Jswat – Open source Java
 Xdebug – PHP

10
Examples…

 Assembler
» Assembly language to machine language
» Mnemonics to machine code
» Produces executable machine code
» Pattern of bits
 Interpreter
» High level language to machine language
» Executes immediately

11
Need for System Software

 Controls some of the aspects of operation of


computers.
» File operation
» I/O operation
» Memory management
» Etc.

12
System Software and Machine
Architecture

 One characteristic in which most system software differ


from application software is machine dependency.
» e.g. assembler translate mnemonic instructions into machine code
– The instruction formats, addressing modes, etc., are the direct concern of
assembler design.
» e.g. compilers must generate machine language code
– Generates machine language code, taking into account such hardware
characteristics as number, types of register and the machine instructions
available.
» Therefore, they are usually related to the architecture of the machine on
which they are to run.
» e.g. operating systems are directly concerned with the
» management of nearly all of the resources of a computing system
 Some aspects of system software that do not directly
depend upon the type of computing system
» e.g. general design and logic of an assembler and compiler
13
» e.g. some of the compiler code optimization techniques are independent
The Simplified Instructional Computer (SIC)

 SIC is a hypothetical computer that includes the


hardware features most often found on real
machines.
 Why SIC?
» Not to get confused in the idiosyncrasies of any
particular machine.
» Understand system software at a generic level.
 This machine has been designed to illustrate the
most commonly encountered hardware features and
concepts, while avoiding most of the idiosyncrasies
that are often found in real machines.
14
SIC…

 Two versions of SIC


» SIC - standard model
» SIC/XE (extra equipments or extra expensive)
– SIC program can be executed on SIC/XE
(upward compatible)
– Upward compatible
 Object program for the standard SIC machine will execute
properly on SIC/XE system.

15
SIC Machine Architecture

 Memory
» Consists 8-bit bytes
» Any 3 consecutive bytes form a word (24 bits)
– All addresses in SIC are byte address.
– Words are addressed by the location of their lowest
numbered byte.
» Total of 215 (32,768) bytes in the computer
memory
 Least significant part of a numeric value is stored at the
lowest numbered address

16
SIC…

 Registers
» Five registers, each have 24 bit in length
Register Number Function Use
A 0 Accumulator Arithmetic operations
X 1 Index register Addressing
L 2 Linkage Storing return address for subroutine
register jump instruction (JSUB)
PC 8 Program Contains Address of next instruction to
counter be fetched for execution
SW 9 Status word Flags, other information including
Condition Code (CC)

Note: the numbering scheme is chosen for compatibility with XE version of SIC
17
SIC…

 Data Formats
» Integers are stored as 24-bit binary numbers
» 2’s complement for negative values
» 8-bit ASCII for characters
» No floating point hardware in standard SIC
 Instruction Formats
» 24-bit format
» The flag bit x indicates indexed-addressing mode
8 1 15
opcode X address

18
SIC…

 Addressing modes
» 2 addressing modes available
– Indicated by setting of x bit in the instruction
– The table describes how the target address is calculated
from the address given in the instruction

Mode Indication Target address calculation


Direct x=0 TA = address
Indexed x=1 TA = address + (x)

– () indicates the contents of a register or a memory


location
 (x) represents the contents of register x
19
SIC…

 Instruction Set
 SIC provides basic instruction for simple tasks
» load and store registers: LDA, LDX, STA, STX, etc.
» integer arithmetic operations: ADD, SUB, MUL, DIV, etc.
– All arithmetic operations involve register A and a word in
memory, with the result being left in the register
» comparison: COMP
– COMP compares the value in register A with a word in memory,
this instruction sets a condition code CC to indicate the result
» conditional jump instructions: JLT, JEQ, JGT
– these instructions test the setting of CC and jump accordingly
» subroutine linkage: JSUB, RSUB
– JSUB jumps to the subroutine, placing the return address in register L
– RSUB returns by jumping to the address contained in register L 20
SIC…

 Input and Output


» Input and output are performed by transferring 1 byte at a time
to or from the rightmost 8 bits of register A.
» Each devices are assigned unique 8 bit code
» The Test Device (TD) instruction tests whether the addressed
device is ready to send or receive a byte of data
» The condition code is set to indicate the result of the test
» “Less Than,< “ if device is ready; “Equal, =” if device is busy.
» Read Data (RD)
– read a byte from the device to register A
» Write Data (WD)
– write a byte from register A to the device

21
SIC/XE Machine Architecture

 Memory
» Larger Memory
– 220 bytes (1 megabyte) in the computer memory
– Leads to change in instruction formats & addressing modes
 Registers
» Additional registers provided

Mnemonic Number Use


B 3 Base register – used for addressing
S 4 General working register – no special use
T 5 General working register – no special use
F 6 Floating point accumulator (48 bits)

22
SIC/XE Machine…
 Data Formats
» Similar data format as the standard SIC.
» In addition, there is 48 bit Floating-point data type
represented with the following format.
s Exponent fraction
1 11 36
» The absolut value of number represented is,
– frac*2(exp-1024)
 fraction: 0~1
 exponent: 0~2047
 Sign is indicated by ‘s’ (0 = +ve, 1 = -ve)

23
SIC/XE Machine…

 Instruction formats
» The larger memory on SIC/XE mean an address will no longer
fit into 15 bit field.
» Two possible options:
– Use some from of relative addressing
– Or extended the address field to 20 bit
– Both options are included in SIC/XE(format 3 and format 4)
» SIC also provides some instructions that do not reference at all
– Format one
– Format two

24
SIC/XE Machine…
Formats 1 and 2
n: indirect
Instruction Formats do not
reference i: immediate
8 memory at all x: index
Format 1 (1 byte) opcode b: base
8 4 4 p: pc
Format 2 (2 bytes) opcode r1 r2 e: extended
6 111111 12
Format 3 (3 bytes)
opcode n i x b p e disp
e=0
6 111111 20
Format 4 (4 bytes)
opcode n i x b p e Address
e=1
Bit e distinguishes between formats 3 and 4
Large memory extends addressing capacity 25
SIC/XE Machine…

 Addressing modes
 Base relative/b (n=1, i=1, b=1, p=0)
 Program-counter relative/p (n=1, i=1, b=0, p=1)
 Direct/ (n=1, i=1, b=0, p=0)
 Immediate (n=0, i=1, x=0)
 Indirect (n=1, i=0, x=0)
 Indexing (both n & i = 0 or 1, x=1)
 Extended (e=1)
 Note: Indexing cannot be used with immediate or indirect
addressing

26
SIC/XE Machine…

 Base Relative Addressing Mode


n i x b p e
opcode 1 1 1 0 disp

n=1, i=1, b=1, p=0 TA=(B)+disp (0disp 4095)

 Program-Counter Relative Addressing Mode


n i x b p e
opcode 1 1 0 1 disp

n=1, i=1, b=0, p=1 TA=(PC)+disp (-2048disp 2047)


27
SIC/XE Machine…

 Direct Addressing Mode


n i x b p e
opcode 1 1 0 0 disp
n=1, i=1, b=0, p=0 TA=disp (0disp 4095)

n i x b p e
opcode 1 1 1 0 0 disp

n=1, i=1, b=0, p=0 TA=(X)+disp


(with index addressing mode)
28
SIC/XE Machine…

 Immediate Addressing Mode


n i x b p e
opcode 0 1 0 disp
n=0, i=1, x=0 TA = disp

 Indirect Addressing Mode


n i x b p e
opcode 1 0 0 disp

n=1, i=0, x=0 TA=(disp)


29
SIC/XE Machine…

 Simple Addressing Mode


n i x b p e
opcode 0 0 disp

i=0, n=0 TA=b/p/e/disp (SIC standard)

n i x b p e
opcode 1 1 disp

i=1, n=1 TA=disp (SIC/XE standard)

30
SIC/XE Machine…

For formats 3 and 4:


 Immediate addressing mode (n = 0, i =1)
» The target address is used as the operand
 Indirect addressing mode (n = 1, i = 0)
» The word at the location given by the target address is
fetched
» The value contained in this word is then used as the address
of the operand value
 Simple addressing mode
» The target address is taken as the location of the operand
» (n = 1, i = 1) used by SIC/XE
» (n = 0, i = 0) used by SIC
Indexed addressing cannot be used with immediate or indirect modes.
31
SIC/XE Machine…
4: Format 4 instruction
D: Direct-addressing instruction (i.e.,)non-relative addressing b=0 & p=0
A: Assembler selects either program-counter relative or base- relative mode
S: Compatible with instruction format for standard SIC

32
PC-relative simple addressing: (PC) + disp
Base-relative indexed simple addressing: (B) + disp + (X)
PC-relative indirect addressing: (PC) + disp
Immediate addressing: disp
SIC simple addressing: b/p/e + disp
Simple addressing: addr

All of these instructions are LDA.


33
SIC/XE Machine…

 Instruction Set
» new registers: LDB, STB, etc.
» floating-point arithmetic: ADDF, SUBF, MULF, DIVF
» register move: RMO
» register-register arithmetic: ADDR, SUBR, MULR, DIVR
» supervisor call: SVC
– generates an interrupt for OS
 Input/Output
» SIO, TIO, HIO: start, test, halt the operation of I/O device

34
SIC and SIC/XE
Programming Examples

 Data movement operations


 Arithmetic operations
 Looping and indexing operations
 Data input and output operations

35
Programming Examples
WORD – Integer constant BYTE – Character constant

Immediate addressing
makes the program
run faster because it
need not fetch five
from the memory.

RESW - Reserve indicated RESB - Reserve indicated


number of words for a data area number of bytes for a data area
36
36
36
Programming Examples

BETA (ALPHA + INCR - 1)


DELTA (GAMMA + INCR - 1)
Fig: Arithmetic operations SIC 37
Programming Examples
BETA (ALPHA + INCR - 1)
DELTA (GAMMA + INCR - 1)

This program will execute faster because


it need not load INCR from memory
each time when INCR is needed.
38
38
Programming Examples

• During 1st loop exec, T.A. for LDCH will be address of 1st byte of STR1
• ll’ly STCH stores copied character into 1st byte of STR2
• TIX 2 operations
• adds 1 to value in register X
• compares new value in register X to value of operand

Fig: Looping and indexing SIC  Loop copies 11 bit character string to another 39
Programming Examples

• Same as TIX. Value for comparison is taken form another register, not
from memory
• Loop efficient, b’coz value not fetched from memory each time the
loop is executed

Will execute faster because TIXR not compare


Fig: Looping and indexing SIC/XE
the index value to a memoryneed variable 40
Programming Examples

• Loop is cumbersome, b’coz register A is used for adding array elements


& for incrementing the index value

Fig: Looping & indexing SIC Gamma[] Alpha[]41+ Beta[] 41


Programming Examples

This program will execute faster


because it uses register-to-register
Fig: Looping & indexing SIC/XE add to reduce memory accesses. 42
Programming Examples
• Reads 1byte from device F1 & copies to device 05
• Operand for RD is a byte in memory, containing the hexadecimal code
for input device
• Executing RD transfers 1byte data from device F1 to Right Most Byte of
register A
• Before RD is executed, input device must be ready to transmit, by
checking TD instruction
• When TD is executed, status of addressed device is tested & condition
code set to indicate result.
•If device ready, CC is “less than”, else “equal”
• Output too performed the
same way
• 1st TD checks, if O/P
device is ready to receive a
byte
• Byte written into Right
Most Byte of register A
• WD to transmit data to
device
Fig: 43
Programming Examples
• Read operation placed in a subroutine
• Subroutine called from main using JSUB
• At end of subroutine, RSUB, returns control to instruction
following JSUB
• READ subroutine consists of loop
• TD, CC, then RD

Read 100 byte record into buffer


•TIX 2 operations

• adds 1 to
value in
register X
• compares
new value in
register X to
value of
operand
44
Fig: Subroutine call & record input operations SIC 44
Programming Examples
• Immediate addressing
• TIXR instruction

TIXR makes this program run faster

Fig: Subroutine call & record input operations SIC/XE 45


Thank you!

46

Вам также может понравиться