Computer Systems Programming
Dr. Eyas El-Qawasmeh
[email protected] [email protected] Cell Phone: 0795289573
Administrivia
• Books
- System Software – An introduction to Systems
Programming. Third edition, Addison Wesley
Publishing, 1997.
• Grades
– First 15%
– Second 15%
– Student Activities ( homeworks, Quizes, ..) 20%
– Final Exam 50%
Administrivia – cont.
• Sharing / copying exercises
will NOT be tolerated
• Make your cell phone off. Otherwise, you
will be asked to leave the class.
Chapter 1 : Background
• In this chapter we will study the SIC.
• SIC ( Simplified Instructional Computer).
• SIC is used to present fundamental software
concepts.
Fundamentals - Programming
What do we mean by programming?
Instructing a computer in an unambiguous, step by
step manner to perform tasks that will help us solve
some real world problem within finite time.
This real world problem can be in any domain –
business, commerce, finance, engineering,
education, science, arts, health, medicine,
entertainment, …
Fundamentals – Kinds of Programs
Different Kinds of Programming?
End-User Programming:
Word, Excel, Paint, Chat, Explorer, …
Utilities and Analysis Programming:
Visual Basic, Javascript, HTML, Format conversion, …
Applications Programming:
Banking, Engineering, Education, GIS, …
Systems Programming:
Assemblers, Loaders, Compilers, Device Drivers, OS, …
Fundamentals – The Big Question
What is the Ultimate Goal?
Reduce the communication gap between humans and computers.
01010101
Utilities & 11111001
End-User Applications Systems
Analysis 01001000
Fundamentals – Purpose of Study
Why Should You study Systems Programming?
This is the kind of knowledge that will distinguish a computer science/software
engineering graduate from others who claim to be great programmers.
You are more than a mere user of computer systems. You know
the inner functioning!!!
The programs are complex, and there are some beautiful techniques used (data structures,
algorithms, formal models). These you will treasure throughout your professional life.
Essential for jobs in embedded programming!!!
Course Objective
Describe the operation of, and discuss data
structures, algorithms and design options of the
following types of System Software:
Assemblers
Linkers and loaders
Compilers and Interpreters
Operating systems
Upon completion of this course, you will be :
Able to design and program a simple Assembler/Compiler,
Loader and Interpreter.
Know the architecture, structure and techniques in an
Operating System, and
Ready for the detailed Operating Systems Design course.
Introduction
Definition
System software consists of a variety of programs
that support the operation of a computer
Example:
e.g. when you took your first programming course
text editor, compiler, loader or linker, debugger
e.g. if you wrote any assembly language programs
assembler, macro processor
e.g. you invoked all of these processes and used
devices like printers, keyboard etc.
interacting with the operating system
System Software vs. Machine Architecture
One characteristic in which system software differs from application
software is machine dependency
e.g. assembler translates mnemonic instructions into machine
code
e.g. compilers must generate machine language code
e.g. operating systems are directly concerned with the
management of nearly all of the resources of a computing
system
There are however 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
e.g. code optimization techniques
• If you write a program in the assembly
language, then you might used macro
instructions in this program to read/write
data and perform other functions. You used
an assembler, which mostly included a
macro processor, to translate this program
into machine language program. The
translated program were prepared for
execution by the loader or linker, and may
have been tested using the debugger.
Organization of a Computer System
• A computer system consists of
– hardware
– system programs
– application programs
What is the difference between system
software and application software ?
• An application software is primarily
concerned with the solution of some
problem, using the computer as a tool.
• System programs are intended to support
the operation and use of the computer itself,
rather than any particular application.
For this reason, system programs are usually
related to the architecture of the machine on
which they are to run.
Assemblers
• Translate mnemonic instructions into
machine code.
• The instruction formats, addressing modes,
etc. are of direct concern in assembler
design.
Compilers
• Must generate machine language code,
taking into account the hardware
characteristics as the number and type of
registers and the machine instructions
available.
Note
• There are some aspects of system software that do not
directly depend upon the type of computing system being
supported.
• Example 1 : The general design and logic of an assembler
is basically the same on most computers.
• Example 2: Some of the code optimization techniques
used by compilers are independent of the target machine.
• Example 3: The process of linking together
independently assembled subprograms does not usually
depend on the computer being used.
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 embroiled in the idiosyncrasies of any particular
machine.
Understand system software at a generic level.
Two versions of SIC
standard model
SIC/XE version
(SIC programs are upward compatible. Will run on SIC/XE)
SIC Machine Architecture
Memory
8-bit bytes
3 consecutive bytes form a word – addressed by lowest
numbered byte
Byte addressable 215 bytes of memory
Registers (24 bits each, total 5 in number)
Mnemonic Number Special use
A 0 Accumulator; used for arithmetic operations
X 1 Index register; used for addressing
L 2 Linkage register; JSUB
PC 8 Program counter
SW 9 Status word, including CC
SIC Machine Architecture
Data Formats
Integers are stored as 24-bit binary numbers; 2’s complement
representation is used for negative values, 8 bit ASCII for characters.
No floating-point hardware.
Instruction Formats
opcode (8) x address (15)
Addressing Modes
Mode Indication Target address calculation
Direct x=0 TA=address
Indexed x=1 TA=address+(X)
SIC Machine Architecture
Instruction Set
load and store: 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
SIC Machine Architecture
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
The Test Device (TD) instruction tests whether the addressed
device is ready to send or receive a byte of data
“Less Than “ if device is ready; “Equal” if device is busy.
Read Data (RD)
Write Data (WD)
SIC/XE Machine Architecture
Larger Memory
220 bytes in the computer memory
More Registers
Mnemonic Number Special use
B 3 Base register; used for addressing
S 4 General working register
T 5 General working register
F 6 Floating-point acumulator (48bits)
Floating Point Registers and Instructions
More addressing modes
SIC/XE Machine Architecture
Data Formats
Floating-point data type: frac*2(exp-1024)
frac: 0~1
exp: 0~2047
s exponent fraction (36)
(11)
Instruction Formats
larger memory -> extend addressing capacity
Format 1
op(8)
Format 2
op(8) r1(4) r2(4)
Format 3 e=0
op(6) n I x b p e disp(12)
Format 4 e=1
op(6) n I x b p e address (20)
SIC/XE Machine Architecture
Addressing Modes
Mode Indication Target address calculation
Base relative b=1, p=0 TA=(B)+disp (0<=disp<=4095)
Program-counter b=0, p=1 TA=(PC)+disp (-2048<=disp<=2047)
relative
Direct b=0, p=0 TA=disp (format 3) or address (format 4)
Indexed x=1 TA=TA+(X)
How the target address is used?
Mode Indication operand value
immediate addressing i=1, n=0 TA
indirect addressing i=0, n=1 (TA)
simple addressing i=0, n=0 SIC instruction (all end with 00)
i=1, n=1 SIC/XE instruction
Note: Indexing cannot be used with immediate or indirect addressing
SIC/XE Machine Architecture
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
HOME READING/WORK
The following Figure F.2 move 3-byte word into
a register then move 1-byte (contains
character) only
SIC Programming Examples (Fig 1.2)
The following figure 1.3 compute (alpha+incr
-1) and store it in beta using SIC and SIC/XE
SIC Programming Example (Fig 1.3)
HOME READING/WORK
The following fig 1.4 writes an assembly
program to copy 11-byte character string to
another.
SIC Programming Example (Fig 1.4)
HOME READING/WORK
You have arrays ALPHA, BETA, and GAMMA,
each one consists of 100 words. Add the
corresponding elements of ALPHA and BETA
and store the result in GAMMA. ( The solution is
in following figure 1.5
SIC Programming Example (Fig 1.5)
HOME READING/WORK
Write a simple program that demonstrate a
simple example of input and output on SIC and
on SIC/XE. The solution is in Fig 1.6 in the text
book which I already copied it and distribute it
in the class
Write a program that call a subroutine that
reads a 100-byte record from an input device
into memory. The solution is in the text Figure
1.7. I already distribute the solution in the class
Computer Architecture Review
Basic computer components
Monitor
Bus
Structure of a large Pentium system
We will skip the material from the beginning of
section 1.4 to the end of chapter 1. We might
come back for it later. However, you must solve
all the questions at the end of chapter 1
Home Work No. 1
• Due date is July 22 hardcopy.
• Solve one question only using the assembler
which I will inform you about it.
• The question is as follows :No mod 10.
• However, if you get 1 then solve 11
• If you get 2 then solve 12.
• If you get 3 then solve 13.
• If you get 0 then solve 10
Assembler resources
• The following URL contains assembler of
the SIC
• http://cis.csuohio.edu/~somos/cis335
• Please visit the above address and
download the assembler.
• It contains readme file
Q1 page 40
• Write a sequence of instructions for SIC to
set ALPHA equal to the product of BETA
and GAMMA. Assume that ALPHA,
BETA and GAMMA are defined as in Fig
1.3 a
LDA BETA
MUL GAMMA
STA ALPHA
BETA RESW 1
GAMMA RESW 1
ALPHA RESW 1
Q2 page 40
Write a sequence of instructions for SIC/XE
to set ALPHA equal to 4*BETA – 9.
Assume that ALPHA and BETA are
defined as in Fig 1.3b. Use immediate
addressing .
LDA BETA
MUL #4
SUM #9
STA ALPHA
BETA RESW 1
ALPHA RESW 1
End of chapter 1