csc225 Lecture Notes-1
csc225 Lecture Notes-1
1
Course Outline
The structure of the Computer System
Representation of numbers in computers
2
Course Objectives
At the end of this course each student should be able to:
1. Describe what a computer system is
2. Explain at least 4 components of a computer system
3. Differentiate between computer software and hardware
4. Give at least five examples each of input and output
devices respectively
5. Enumerate at least 4 categories of application software
6. Demonstrate how integer numbers are stored in the
computer memory
7. Perform basic binary arithmetic
8. Define assembly language and explain its basic syntax
9. State at least 4 advantages of assembly language
programs
10. Explain sample assembly language mnemonics
3
What is a computer
System?
A computer system can be defined as an
electronic device, operating under the control
of instructions stored in its own memory, that
can accept data (input), process the data
according to specified rules (process), produce
results (output) and stores the results
(storage) for future use. Generally, the term
computer system is used to describe a
combination of electro-mechanical
components known as hardware and a suite
of programs and data referred to as software.
4
printer
(output device)
monitor
(output device)
system unit
(processor, memory,
mouse
and storage devices)
keyboard (input device)
(input device)
modem
(communications
device)
memory cards
(storage device) external hard disk
(storage device)
5
The Components of a Computer
System
There are six primary components of a computer
system namely; input devices, the processor
(control unit and arithmetic/logic unit), memory,
output devices, storage devices, and
communications devices.
The processor, memory, and storage devices are
housed in a box-like case called the system unit or
Central Processing Unit (CPU) as shown in Fig. 1.
A peripheral is a device that connects to the system
unit and is controlled by the processor in the
computer. Peripherals can include input and output
devices, as well as some storage and communications
devices.
6
Input devices
An input device is any hardware component that allows the
user to feed data and instructions into the computer.
Depending on the program requirements, the input device
used may vary. Five commonly used input devices are
keyboard, mouse, microphone, scanner, and Web
cam. For PCs, the two primary input devices used are the
keyboard and the mouse.
A keyboard is an input device that contains keys users
press to enter data and instructions into the computer. All
desktop computer keyboards have a typing area that
includes the letters of the alphabet, numbers, punctuation
marks, and other basic function keys. Many desktop
computer keyboards also have a numeric keypad on the
right side of the keyboard
7
The System Unit
8
sound card
system unit
video card
memory module
processor
9
The Processor
10
Memory
The Memory consists of electronic components
that store instructions waiting to be executed and
data needed by those instructions. Most memory
keeps data and instructions temporarily, which
means its contents are erased when the
computer is off.
This type of memory is referred to as RAM. RAM
(Random Access Memory) consists of memory
chips that can be read from and written into by
the processor and other devices.
11
These chips are placed on a memory module that
fits in a slot on the motherboard.
The memory in computers is measured in
kilobytes, megabytes, gigabytes, or terabytes. A
byte usually stores one character, such as the
letter A.
One kilobyte (KB or K) equals exactly 1,024
bytes, and one megabyte (MB) is about one
million bytes. One gigabyte (GB) is
approximately one billion bytes, and one
terabyte (TB) is approximately one trillion bytes.
12
Output devices
Output devices are hardware components that convey
information from the computer system to one or more
end users.
13
Storage Devices
14
Communications Devices
15
Computer Software
Computer software, also called a program, consists of a
series of instructions, organized for a common purpose,
that tells the computer what tasks to perform and how to
perform them.
A user interacts with a program through its user
interface. The user interface controls how data and
instructions are entered and how information is displayed
on the screen. Software nowadays comes with a
graphical user interface. With a Graphical User Interface
(GUI) one can interact with the software using text,
graphics and visual images such as icons. Computer
software can be categorised into two broad classes
namely system software and application software.
16
a. System Software
17
A utility program allows a user to perform
maintenance-type tasks usually related to
managing a computer, its devices, or its
programs. For example, you can use a
utility program to burn digital photos on an
optical disc. Most operating systems include
several utility programs for managing disk
drives, printers, and other devices and
media.
18
b. Application Software
20
Representation of numbers in computers
Bit
– Single Binary Digit
– Can have value 0 or 1, and nothing else
– A bit is the smallest possible unit of information in a
computer
- Groups of bits can represent data or information
– 1 bit – 2 alternatives 0 or 1
– 2 bits – 4 alternatives 01, 00, 10 or 11
– 3 bits –8 alternatives 000, 001, 010, 011, 100, 101,110, 111
– 4 bits – 16 alternatives 0000, 0001, 0010, 0011, 0100, 0101,
0110, 0111, 1000, 1001,1010, 1011,1100, 1101, 1110, 1111
– 8 bits -28 = 256 alternatives
– n bits – 2n alternatives
– a group of 8 bits is called a byte
21
- 1kbyte = 210 = 1024 bytes
– 1Mbyte = 220= 1048,576 bytes
- 1Gbyte = 230 = 1,073,741,824 bytes
22
Binary Number Representation
of Integers
If we save one bit to signify positive (+) or
negative (-), then an n-bit binary word can
represent integers in the range
-2n-1 -1 .. +2n-1
For example, a 16-bit binary word can
represent integers in the range
-216-1 -1 .. +216-1 = -215 -1 .. +215
-32,767 .. +32,768
23
Exercise 1
Convert the 16-bit binary number 0 0 0 0 0 0
0 11 0 0 1 1 1 1 1 to a decimal number:
Solution:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 (power)
0 0 0 0 0 0 0110011111
= 1 x 2 8 + 1 x 2 7 + 1 x 2 4 +1 x 2 3 + 1 x 2 2
+1x21+1x20
= 256 + 128 + 16 + 8 + 4 + 2 + 1
= 415
24
Let the most significant bit (MSB) signify
positive or negative numbers (1 for negative;
0 for positive)
Exercise 2: Sum -9 and +9 in 16-bits
+9 = 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1
-9 = 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1
Summing the two gives us:
+9 + (-9) = 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0
25
In order to solve the problem in Exercise 2, we
need a different representation for negative
numbers called 2s-complement
Step 1: Take the 1s-complement of the positive
binary number, 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1
Gives us: 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 (Hint:
flip each bit)
Step 2: Add 1 to the result
1111111111110110+
1
__________________________
1111111111110111
(this is the 2s compliment)
26
Step 3:Add the positive binary number to
the 2s compliment as follows:
0000000000001001+
1111111111110111
_____________________________
0000000000000000
This is the correct answer!
27
Hexadecimal (Hex) Notation
28
Consequently:
Binary: HEX:
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 = 0009
1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 = FFF7
29
Assembly Languages
Assembly Languages belong to the family of Low-level
programming languages that provide little or no abstraction
from a computer's Instruction Set Architecture(ISA).
Commands or functions in the language map closely to
processor instructions. These languages let the programmer
have direct access to the resources of the machine (e.g., CPU
Registers, Memory and I/O ports). Although they are machine-
dependent, assembly languages have the following
advantages:
They are easier to understand and use than machine
languages
Assembly language codes are relatively easy to debug
programs
Assembly language programs are often the smallest in size
30
Assembly Language
Syntax
Each assembly line begins with either a label, a blank
(tab), an asterisk, or a semicolon
Each line has four fields namely:
{label[:]} mnemonic {operand list} {;comment}
loop: = label
mov = mnemonic
#COUNT,r5 = operand list
; get counter = comment
31
Label Field
- Labels are symbols
– Labels must begin in column 1
– A label can optionally be followed by a
colon – The value of a label is the current
value of the Location Counter (address within
program)
– A label on a line by itself is a valid
statement – Labels used locally within a
program file must each be unique
32
Mnemonic Field
The Mnemonic Field:
– Follows the label field
– The mnemonic field cannot start in column
1; if it does, it is interpreted as a label
– The mnemonic field contains one of the
following items:
◦ Instruction mnemonic (I.e. ADD, MOV, JMP)
◦ Assembler directive (i.e. .data, .list, .equ)
◦ Macro directive (i.e. .macro, .var, .mexit)
◦ Macro call
33
Operand Field
The operand field follows the mnemonic field
and contains one or more operands
– The operand field is not required for all
instructions or directives
– An operand may consist of:
1. Symbols
2. Constants
3. Expressions (combination of constants and
symbols)
– Operands are separated by commas
34
Machine Language Instruction Set
Category Example
Arithmetic ADD, SUBTRACT, MULTIPLY,
DIVIDE
Logic AND, OR, NOT, EXCLUSIVE OR
Program Control BRANCHING, SUBROUTINES
Data Movement MOVE, LOAD, STORE
Input/Output READ, WRITE
35
Example:
C ++ Language code:
C= A + B;
An equivalent Assembly language code:
ADD r1, r2
where r1 and r2 are registers holding data A
and B respectively
36
Information System
– A system that takes data, stores and processes it,
and provides information as an output
– An IS is a computer in use
– The amount of data can be vast
Communication: the transfer of meaningful
Information. Communication Comprises of the
following:
» the sender (transmitter)
» the channel over which to send the data and
» the receiver
The communication protocol is also very important
for effective communication to take place
37
User interfaces:
– Software which is responsible for passing
information to and from the person using the
computer program
– Communicates with and controls the computer
– There are three common types of user interfaces
namely:
1. Graphic user interfaces: This uses pictures,
graphic symbols (icons) to represent commands
2. Menu driven interfaces: Pull-down menu are
used for user choices
3. Command driven interfaces:User types in
single letter, word or line on a prompt which is
translated into an instruction for the computer
38
Digital Logic Circuits
Design
At the logic level, there are two categories of digital
systems namely:
1. Combinational - digital systems without
memory
2. Sequential - digital systems with memory
For the purpose of this course, emphasis will be
placed on combinational digital circuit systems.
Note that digital signals can only have a fixed
number of values within certain tolerances. In
digital circuitry, these values can only be of two
distinct states namely TRUE or FALSE (i.e., High or
Low).
39
Boolean Algebra
Definition: a logical variable x can have only
one of two possible values or states :
x = TRUE
x = FALSE
In binary notation, we can say
x = TRUE = 1
x = FALSE = 0
This is called positive logic or high-true logic. We could
also say
x = TRUE = 0
x = FALSE = 1
This is called negative logic or low-true logic
Note that the positive logic is conventionally used instead.
40
Logic Gates
Logic gates are switching circuits that
perform certain simple operations on binary
Signals. These operations are chosen to
facilitate the implementation of useful
functions:
a. The AND Logic Operation: Consider the
following circuit diagram. The bulb lights on
when both A and B switches are ON or TRUE.
If any only one is ON or TRUE, the circuit is
still broken implying that the bulb won’t light.
41
A B
+
-
42
The circuit diagram of the AND gate is as
shown below:
A
F=A.B
B
43
A
B
+
-
44
The circuit diagram of the OR gate is as
shown below:
A
F=A+B
B
45
The truth table of the NOT logic operation is
given below:
A F= NOT A
0 1
1 0
A F=Ä
46
d. The NAND Logic Operation: This is a
combination logic comprising of both AND
and NOT operations. The truth table of the
NAND logic is as shown below:
A B F= A NAND B
0 0 1
0 1 1
1 0 1
1 1 0
47
A
____
F=A.B
B
48
The NOR logic gate is as shown below:
A
____
F=A+B
B
A
F=A⊕B
B
50
Rules and Laws of Boolean Algebra
Operations on Boolean variables are defined
and governed by laws, the most important of
which are presented as follows:
1. Commutative Law: This law states that
the order of the variables is not important.
E.g.;
A.B=B.A
A+B=B+A
51
2. Associative Law: This law states that the
grouping of the variables is unimportant.
Example:
A . (B . C) = A . (B . C)
A + (B + C) = A + (B + C)
3. Distributive Law: This law states that we
can remove the parenthesis by ‘multiplying
through’. For example:
A . (B + C) = A . B + A . C
The above laws are the same as in algebra,
where ‘+’ and ‘.’ are interpreted as addition
and multiplication respectively.
52
DeMorgan’s Laws of Boolean
Algebra
Law (1): ____ __ __
A+B=A.B
The law reads as follows:
“NOT (A OR B) = NOT A AND NOT B”.
The truth table below provides prove for the
law:
____ _ _ _ _
A B A+B A+B A B A. B
0 0 0 1 1 1 1
0 1 1 0 1 0 0
1 0 1 0 0 1 0
1 1 1 0 0 0 0
53
Law(2): ____ _ _
A.B=A+B
The second law reads :
“NOT (A AND B) = NOT A OR NOT B”
The truth table below provide the proof.
___ _ _ _ _
A B A.B A.B A B A+ B
0 0 0 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1
1 1 1 0 0 0 0
55
4 Show how an 8-bit computer system would
carry out the following binary arithmetic
a. -6 + 9
b. 12 – 8
56