0% found this document useful (0 votes)
47 views

Chapter 1 - Introduction

The document discusses systems programming and provides an overview of key concepts. It describes how systems programming was foundational to all early computer programming and underlies software that provides services to other programs. Examples of system software include operating systems, compilers, and file systems. The document also discusses machine architecture and how system software depends on and is tailored to specific CPU architectures. It introduces SIC as a hypothetical computer system used to teach core computer concepts without real-world complexity.

Uploaded by

Firomsa Tesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Chapter 1 - Introduction

The document discusses systems programming and provides an overview of key concepts. It describes how systems programming was foundational to all early computer programming and underlies software that provides services to other programs. Examples of system software include operating systems, compilers, and file systems. The document also discusses machine architecture and how system software depends on and is tailored to specific CPU architectures. It introduces SIC as a hypothetical computer system used to teach core computer concepts without real-world complexity.

Uploaded by

Firomsa Tesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Chapter 1: Introduction

Overview
Simplified Instructional Computer
Traditional Machine Structure
Systems Programming Languages
Systems Programming (Compiled by: Kidane W.) 11/19/2018 1
History of Computer Programming
• One of the difficulties of discussing the historical origins of a subject is to decide
where to begin.
• It is probably fair to say that the first program-controlled (mechanical) computer
ever build was the Z1 (1938).
• This was followed in 1939 by the Z2 as the first operational program controlled
computer with fixed-point arithmetic.

Systems Programming (Compiled by: Kidane W.) 11/19/2018 2


Overview[1]
• In the beginning, all programming could be considered “Systems
programming”
• With the advent of increasingly powerful machines and ever more
featureful runtime environments, programming languages moved away
from systems programming to application programming

Computer Components Hierarchy

Systems Programming (Compiled by: Kidane W.) 11/19/2018 3


Overview[2]
• The technological advances witnessed in the computer industry
are the result of a long chain of immense and successful efforts
made by two major force:
• The academia, represented by university research centers, and
• The industry, represented by computer companies.

Systems Programming (Compiled by: Kidane W.) 11/19/2018 4


Overview[3]
• Systems Programming is a practice of writing “system software” and it is at the
heart of all software that we write
• It provides service for other software (e.g. kernels, libraries, daemons)
• Typically resource (memory or CPU) constrained
• Used to build abstraction for application programmers

Systems Programming (Compiled by: Kidane W.) 11/19/2018 5


Overview[4]
• Some examples of System Software
• Compiler (people like language into machine language translator)
• Assembler
• Loader(Prepare machine language for Execution)
• Macro processor(Allows abbreviation usage)
• Operating Systems and File System (Flexible information storage and retrieval)
• Shells and Windowing Systems

Systems Programming (Compiled by: Kidane W.) 11/19/2018 6


Overview[5]
• System Software consists of programs that supports the operation of a
computer.
• This software makes its possible for the user to focus on an application
without needing to know the detail of how the machine works internally.

Foundations of Systems Programming

Systems Programming (Compiled by: Kidane W.) 11/19/2018 7


Overview[6]
System Software Application Software
Used for operating computer hardware Used by user to perform specific task
Installed on the computer when operating system is Installed according to user’s requirements
installed.
The user does not interact with system software The user interacts with application software.
because it works in the background
Run independently Can’t run without the presence of system
software
Example: (compiler, assembler, debugger, loader, etc) Example: (word processor, web browser, media
player, etc.)
Systems Programming (Compiled by: Kidane W.) 11/19/2018 8
Overview[7]
• Evolution of the Components of a programming System
1. Assemblers ( Source program  Object program)
2. Loaders (Place object program in memory in an executable format)
3. Macros (allows programmers to use abbreviations)
4. Compilers
5. Formal Systems

Systems Programming (Compiled by: Kidane W.) 11/19/2018 9


Overview[8]
• System Software Requirements
• Space/time economy
• Access to all relevant hardware features
• Object code must not depend upon elaborate run-time support

Systems Programming (Compiled by: Kidane W.) 11/19/2018 10


Overview[9]
• Characteristics of Systems Programming
• Programmers are expected to know hardware and internal behavior of the computer
system on which the program will run
• Use low level programming languages or some programming dialects
• Requires little run time overheads and can execute in a resource constrained
environment
• Small or no runtime libraries requirements
• Have access to system resource, including memory
Systems Programming (Compiled by: Kidane W.) 11/19/2018 11
Overview[10]
• Systems Programming Limiting Factors
• No debugging mode running support
• Limited programming facilities
• Less runtime libraries
• Less error checking capabilities

Systems Programming (Compiled by: Kidane W.) 11/19/2018 12


Overview[11]
• Ever wonder why you can’t insert a PlayStation CD in your desktop
computer and start playing the game? Or why you can’t run iPhone apps on a
Mac?
• The reason is simple: different CPU architectures
• A different CPU architecture means a different CPU instruction set, thus a different way to encode
instructions as numbers.
• Numbers that translate as instructions for your desktop CPU don’t represent valid instructions for the
CPU in your cell phone, and vice versa.

Systems Programming (Compiled by: Kidane W.) 11/19/2018 13


Machine Architecture[1]
• The system software like assembler, linker and loader are all dependent on
machine architecture
• One characteristic in which most system software differ from application
software is machine dependency:
• Assembler translate mnemonic instructions into machine code
• Compilers must generate machine language code

Systems Programming (Compiled by: Kidane W.) 11/19/2018 14


Machine Architecture[2]
• System Software usually related to the architecture of the machine on which they are to
run
• Some aspects of system software that do not directly depend upon the type of computing
system (General design and logic of an assembler and compiler)
• A different definition of computer architecture is built on four basic viewpoints:
• Structure (interconnection of various hardware components)
• Organization (dynamic interplay and management of the various components)
• Implementation (design of hardware components), and
• Performance (specifies the behavior of the computer system).

Systems Programming (Compiled by: Kidane W.) 11/19/2018 15


Machine Architecture[3]
• Architecture Feature Descriptors:
• System Memory (used to store programs and data)
• Registers
• Instruction Formats
• Data Formats
• Addressing Mode
• Instruction Set
• Input/Output
Systems Programming (Compiled by: Kidane W.) 11/19/2018 16
Machine Architecture[4]
• The CPU works in a never-ending cycle, always fetching and executing an instruction from
memory.
• Execution Life Cycle (fetch-execute cycle):
1. The next instruction to be executed, whose address is obtained from the PC, is fetched from the memory and stored in
the IR.
2. The instruction is decoded.
3. Operands are fetched from the memory and stored in CPU registers, if needed.
4. The instruction is executed.
5. Results are transferred from CPU registers to the memory, if needed.

Systems Programming (Compiled by: Kidane W.) 11/19/2018 17


Simplified Instructional Computer
• SIC is a hypothetical computer system architecture designed for
teaching computer systems programming
• 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.
• Two versions of SIC:
• SIC - standard model
• SIC/XE (extra equipment or extra expensive)
Systems Programming (Compiled by: Kidane W.) 11/19/2018 18
SIC Memory
• Memory storage in SIC consists of 8-bit bytes, and all memory addresses in
SIC are byte addresses.
• 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 of total memory


• Least significant part of a numeric value is stored at the lowest numbered address

Systems Programming (Compiled by: Kidane W.) 11/19/2018 19


SIC Registers

• The CPU has some internal memory cells called registers.


• It can perform simple mathematical operations with numbers stored in these
registers.

• Note: the numbering scheme is chosen for compatibility with XE version of SIC
Systems Programming (Compiled by: Kidane W.) 11/19/2018 20
SIC Data Formats
• Integers: stored as 24-bit binary numbers
• 2’s complement representation for negative values
• No floating point hardware in standard SIC
• Characters: 8-bit ASCII

Systems Programming (Compiled by: Kidane W.) 11/19/2018 21


SIC Instruction Formats
• 24-bit format
• The flag bit x indicates indexed-addressing mode

Systems Programming (Compiled by: Kidane W.) 11/19/2018 22


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

• (x): represents the contents of register x


Systems Programming (Compiled by: Kidane W.) 11/19/2018 23
SIC Instruction Set[1]
• The collection of all operations a CPU can do is called its instruction set.
• 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

Systems Programming (Compiled by: Kidane W.) 11/19/2018 24


SIC Instruction Set[2]
• 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

Systems Programming (Compiled by: Kidane W.) 11/19/2018 25


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
• 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
Systems Programming (Compiled by: Kidane W.) 11/19/2018 26
SIC Programming Example[1]
(Data movement)

Systems Programming (Compiled by: Kidane W.) 11/19/2018 27


SIC Programming Example[2]
(Arithmetic operations: BETA = ALPHA+INCR-1)

Systems Programming (Compiled by: Kidane W.) 11/19/2018 28


SIC Programming Example[3]
(Looping and indexing: copy one string to another)

Systems Programming (Compiled by: Kidane W.) 11/19/2018 29


SIC Programming Example[5]
(Input and output)

Systems Programming (Compiled by: Kidane W.) 11/19/2018 30


SIC/XE
• Enhanced version of the SIC machine:
• more addressing modes,
• floating point instructions,
• interrupts,
• virtual memory and memory protection features.

Systems Programming (Compiled by: Kidane W.) 11/19/2018 31


SIC/XE Memory
• Larger Memory
• 220 bytes (1 megabyte) in memory
• Leads to change in instruction formats & addressing modes

Systems Programming (Compiled by: Kidane W.) 11/19/2018 32


SIC/XE Registers
• 3 additional registers, 24 bits in length
• 1 additional register, 48 bits in length

Systems Programming (Compiled by: Kidane W.) 11/19/2018 33


SIC/XE Data Formats
• Similar data format as the standard SIC.
• In addition, there is 48 bit Floating-point data type represented with the following format.

• The absolute value of number represented as:


• frac*2(exp-1024)
• fraction: 0~1
• exponent: 0~2047
• Sign is indicated by ‘s’ (0 = +ve, 1 = -ve)

Systems Programming (Compiled by: Kidane W.) 11/19/2018 34


SIC/XE Instruction formats[1]
• 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(e=0) and format 4(e=1))

Systems Programming (Compiled by: Kidane W.) 11/19/2018 35


SIC/XE Instruction formats[2]

Systems Programming (Compiled by: Kidane W.) 11/19/2018 36


SIC/XE Instruction formats[3]
• Format 3 (3 bytes): eg. LDA #3 ( Load 3 to A)

1 1 1 1 1 1

opcode n i x b p e displacement

6 bit 12 bit

0000 00 n i x b p e 0000 0000 0011

Systems Programming (Compiled by: Kidane W.) 11/19/2018 37


SIC/XE Instruction formats[4]
• Format 4 (4 bytes): Eg (–+JSUB RDREC ( jump to address , 1036))

opcode n i x b p e address

6 bit 20 bit

0100 10 1 1 0 0 0 1 0000 0001 0000 0011 0110

4 0 1 0 3 6

Systems Programming (Compiled by: Kidane W.) 11/19/2018 38


SIC/XE Addressing Mode[5]
● 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

Systems Programming (Compiled by: Kidane W.) 11/19/2018 39


SIC/XE Addressing Mode[2]
 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)
Systems Programming (Compiled by: Kidane W.) 11/19/2018 40
SIC/XE Addressing Mode[3]
 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)
Systems Programming (Compiled by: Kidane W.) 11/19/2018 41
SIC/XE Addressing Mode[4]

 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)
Systems Programming (Compiled by: Kidane W.) 11/19/2018 42
SIC/XE Addressing Mode[5]
 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)
Systems Programming (Compiled by: Kidane W.) 11/19/2018 43
SIC/XE Addressing Mode[5]

Systems Programming (Compiled by: Kidane W.) 11/19/2018 44


SIC/XE 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

Systems Programming (Compiled by: Kidane W.) 11/19/2018 45


SIC/XE Input/Output
• 1 byte at a time, TD, RD, and WD
• SIO, TIO, HIO:
• start, test, halt the operation of I/O device

Systems Programming (Compiled by: Kidane W.) 11/19/2018 46


SIC/XE Programming Example[1]
(Sample Data Movement Operations)

SIC version SIC/XE version

Systems Programming (Compiled by: Kidane W.) 11/19/2018 47


SIC/XE Programming Example[2]
(Sample Arithmetic Operations)
SIC version SIC/XE version

Systems Programming (Compiled by: Kidane W.) 11/19/2018 48


SIC/XE Programming Example[3]
(Sample Looping and Indexing Operations)

SIC version SIC/XE version

Systems Programming (Compiled by: Kidane W.) 11/19/2018 49


Traditional (CISC) Machines
• Complex Instruction Set Computers (CISC)
• complicated instruction set
• different instruction formats and lengths
• many different addressing modes
• e.g. VAX or PDP-11 from DEC
• e.g. Intel x86 family
• Reduced Instruction Set Computer (RISC)
Systems Programming (Compiled by: Kidane W.) 11/19/2018 50
Reading Assignments
• VAX Architecture
• Pentium Pro Architecture

Systems Programming (Compiled by: Kidane W.) 11/19/2018 51


RISC Machines[1]

• Instruction
• standard, fixed instruction format
• single-cycle execution of most instructions
• memory access is available only for load and store instruction
• other instructions are register-to-register operations
• a small number of machine instructions, and instruction format
Systems Programming (Compiled by: Kidane W.) 11/19/2018 52
RISC Machines[2]
• Large number of general-purpose registers
• Small number of addressing modes
• Three RISC machines
• SPARC family
• PowerPC family
• Cray T3E
Systems Programming (Compiled by: Kidane W.) 11/19/2018 53
Systems Programming Languages
• In modern programming languages, there exists a distinct lack of languages targeted at
systems programming.
• Most modern languages are designed for application development which is most certainly
valid in the modern world. However, systems programming has been left behind in language
development.
• As such, systems programs do not benefit from the modern developments in language
design.
• Examples of System Programming Languages
• C/C++, D, Go, Rust
Systems Programming (Compiled by: Kidane W.) 11/19/2018 54
Systems Programming Languages

Systems Programming (Compiled by: Kidane W.) 11/19/2018 55


Practical Session
• Quick tour of C: This section can assist the reader who has not yet studied C but
has studied an introduction to programming in a related language, such as C++ or
Java.
• Introduction to Rust
• System Programming
• One pass assembler
• Two pass assembler
• Macro processor
• Loader and Linker
Systems Programming (Compiled by: Kidane W.) 11/19/2018 56
Requirements for RUST
• https://www.rust-lang.org/downloads.html
• https://www.rust-lang.org/en-US/friends.html
• Rust compiler (rustc) installation
• Rust package manager (Cargo)

Systems Programming (Compiled by: Kidane W.) 11/19/2018 57


Chapter 1}
Chapter 2{

Systems Programming (Compiled by: Kidane W.) 11/19/2018 58

You might also like