week1-intro323
TRANSCRIPT
-
8/2/2019 week1-intro323
1/34
ihs/CSCS323/Spring 2012 1
CSCS 323
Course Title Computer Organization with Assembly Language
Course Code COMP 323
Credits 3
Instructor Dr. Iftikhar Hussain Shah
Recommended Books / Material
Assembly Language Programming and Organization of the IBM PC
by Ytha Yu and Charles Marut (McGraw-Hill)
-
8/2/2019 week1-intro323
2/34
ihs/CSCS323/Spring 2012 2
A Computer System
What is a computer?
A computer is an electronic machine which can read, store,
retrieve, process and display information. What is a Computer System?
A computer system consists of two major components:
1. HardwareIt consists of circuits which can read, store, retrieve,process and display information.
2. SoftwareIt consists of programs which:
a. drive the computer (Operating System)
b. facilitate users to perform specific jobs such as word processing(Application Software).
-
8/2/2019 week1-intro323
3/34
ihs/CSCS323/Spring 2012 3
Number Systems
A number system consists of digits.
The number of digits in a number system is called its base.
The following four number systems are commonly used.
Number System Digits Base
Decimal 0-9 10
Binary 0,1 (bits) 2Octal 0-7 8
Hexadecimal 0-9, A-F (A=10, F=15) 16
-
8/2/2019 week1-intro323
4/34
ihs/CSCS323/Spring 2012 4
Conversion from Decimal to Binary
First divide the decimal number by 2 and then repeatedly divide
the quotient by 2 until the quotient becomes o. The remainders taken in the reverse order form the binaryequivalent of that decimal number.
Example: The binary equivalent of 23 is calculated below.
2 23
2 11 1
2 5 1
2 2 1
2 1 0
2 0 1
(23)10 = (10111)2
Base
-
8/2/2019 week1-intro323
5/34
ihs/CSCS323/Spring 2012 5
Conversion from Binary to Decimal
Multiply rightmost bit by 20, next on left by 21, next by 22
and so on. Then add all the products. This gives the decimalequivalent of the given binary number.
Example:
(10111)2 = 1*20
+ 1*21+ 1*22
+ 0*23
+ 1*24
= (23)10
-
8/2/2019 week1-intro323
6/34
ihs/CSCS323/Spring 2012 6
Representation of Numbers
(10111)2is binary number; it can also be written as 10111b or
10111B where b or B indicate that the preceding number is
binary.
Similarly, H or h are used to represent a hexadecimal number,
D or d are used to represent a decimal number & O or o are
used to represent an octal number.
The default is a decimal number; e.g. 101B is binary number
(equivalent to 5 in decimal, while 101 is a decimal number
representing one hundred and one.
-
8/2/2019 week1-intro323
7/34
ihs/CSCS323/Spring 2012 7
Conversion from Decimal to Hexadecimal
First divide the decimal number by 16 and then repeatedly
divide the quotient by 16 until the quotient becomes o. The remainders taken in the reverse order form thehexadecimal equivalent of that decimal number.
Example1: The hex. equivalent of 37 is calculated below.
(37)10 = (25)16
Ex.1. Show that (140)10 = (8C)16
Ex.2. Compute hex. Equivalents of the following decimal numbers:
16, 32, 255, 256, 2047
16 37
16 2 5
0 2
-
8/2/2019 week1-intro323
8/34
ihs/CSCS323/Spring 2012 8
Conversion from Hex. to Decimal
Multiply rightmost digit of the hex number by 160, next on left by
161
, next by 162
and so on. Then add all the products. This givesthe decimal equivalent of the given binary number.
Example:
(25)2 = 5*160
+ 2*161
= (37)10
Ex. Write down a general rules for convertinga decimal number to an equivalent number
in any other system and vice versa.
-
8/2/2019 week1-intro323
9/34
ihs/CSCS323/Spring 2012 9
Conversion from Hexadecimal to Binary
Two methods:
1. Convert hex to decimal and then decimal to binary.
2. Replace each digit of the hexadecimal number by its four-bitbinary representation.( This is commonly used)
Examples:
(25)16 = (00100101)2 or 25h = 00100101b
(8C)16 = (10001100)2 or 8Ch = 10001100b
EX. Convert the following hex. numbers to their binary equivalents andcheck the result: 0A7Dh, 48GDh
-
8/2/2019 week1-intro323
10/34
ihs/CSCS323/Spring 2012 10
Conversion from Binary to Hexadecimal
Two methods:
1. Convert binary to decimal and then decimal to hex.
2. Starting from right form groups of bits each consisting of four bitsof the given binary number. If the last group does not contain 4bits place required 0s to its left. Then replace each group of four
bits by it hexadecimal equivalent.
Examples:
100101b = 00100101b = 25h
10001100b = 8Ch
EX. Convert the following hex. numbers to their binary equivalents and
check the result: 0A7Dh, 48GDh
25
-
8/2/2019 week1-intro323
11/34
ihs/CSCS323/Spring 2012 11
Octal Number System
Assignment:
What is an Octal number system?How would you convert a number from:
1. Decimal to octal and vice versa
2. Octal to binary and vice versa
-
8/2/2019 week1-intro323
12/34
ihs/CSCS323/Spring 2012 12
Language of Computer
A computer understands machine language only. In this language, everything
is expressed in terms of 0s and 1s (Bit Patterns).
The bit
The bit stands for a binary digit, and it can be either 0 or 1. A bit cannot store
much information. To store meaningful information, we use a collection of 8,
16, 32, bits. The Byte
A collection of 8 bits is called a Byte. It can store a character in some way
and is also called a cell.
The Word
A word can be 1, 2, 4, 8, bytes is called a word.
-
8/2/2019 week1-intro323
13/34
ihs/CSCS323/Spring 2012 13
Representation of Information The information consists of letters, digits, punctuation symbols and other
symbols; these are called characters.
A unique integer code has been assigned to each character; inside
computer a character is represented by the eight bit binary equivalent of
its code so that it can fit into a byte of memory.
A few coding systems have been developed for this purpose; the most
common coding system is American Standard Code for Information
interchange (ASCII).
-
8/2/2019 week1-intro323
14/34
ihs/CSCS323/Spring 2012 14
Exercise
How is information represented inside thecomputer. Write a detailed note ondifferent coding Systems.
-
8/2/2019 week1-intro323
15/34
ihs/CSCS323/Spring 2012 15
Example (ASCII CODES)
-
8/2/2019 week1-intro323
16/34
ihs/CSCS323/Spring 2012 16
Logic instructions
o Logic instructions can be used to change individual bits in the computer
o The truth tables for the logic operators AND, OR, XOR & NOT shown in fig.Here a, b are logic / bit variables whose values cab be 0 (false),1(true)
a b a AND b a OR b a XOR b
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
a NOT a
0 1
1 0
L i i i
-
8/2/2019 week1-intro323
17/34
ihs/CSCS323/Spring 2012 17
Logic instructions (continued)
o Logic instructions can be used to change individual bits in the computero The truth tables for the logic operators AND, OR, XOR, NOT are shown in fig.
Here a, b are logic / bit variables whose values cab be FALSE (F), TRUE (T).
a b a AND b a OR b a XOR b
F F F F F
F T F T T
T F F T T
T T T T F
a NOT a
F T
T F
-
8/2/2019 week1-intro323
18/34
ihs/CSCS323/Spring 2012 18
Signals and Buses
A signal consists of a bit pattern.
Processor uses signals to communicate with memory and I/O circuits.
Signals are of three types: address, data and control signals.
A bus is a collection of wires that can carry signals
Buses are of three types: address bus, data bus and control bus.
-
8/2/2019 week1-intro323
19/34
ihs/CSCS323/Spring 2012 19
Input / Output Ports
I/O devices are connected to the computer through circuits. Each of these
circuits contain several registers called I/O ports.
These registers are identified by their addresses. These addresses are used in
I/O operations only.
I/O ports act as transfer points between the CPU and I/O devices.
An input device places data into a port from where CPU reads it.
To output, the CPU places data in the port from where the output
device reads it.
-
8/2/2019 week1-intro323
20/34
ihs/CSCS323/Spring 2012 20
Input / Output Ports
Serial and Parallel Ports
Serial ports transfer data one bit at a time
Parallel ports transfer 8, 16, bits at a time
Slow devices like keyboard are connected to serial ports
Fast devices like disk drives are connected to parallel ports.
Printer can be connected to any port.
-
8/2/2019 week1-intro323
21/34
ihs/CSCS323/Spring 2012 21
Execution of an Instruction (Fetch-Execute Cycle)
The CPU performs the following steps to execute a Machine Language instruction;
these steps constitute Fetch-Execute Cycle. A machine instruction has two
components:
Opcode : specifies type of operation
Operands : are usually registers or memory addresses
Fetch-Execute Cycle
a. Fetch
Bring instructions from the main memory
Decode the instruction into an operation
Fetch data from the main memory
b. Execute
Perform the operation on data
Store result back into the main memory if required
-
8/2/2019 week1-intro323
22/34
ihs/CSCS323/Spring 2012 22
The Clock To ensure that all the steps required to execute a machine language instruction
are performed in an order, a clock circuit controls the processor by generating a
train of pulses.
Period interval between two pulses
Clock speed No. of pulses generated per second
(Unit: Hz, MHz, GHz)
o The 8086 processor had a clock speed of 4.77 MHz
o Now speed are in GHz.
The processing speed depends upon the clock speed.
Computer circuits are activated by clock pulses. Each step in Fetch-Execute cycle
requires one or more clock pulses; e.g. 8086 processor takes 4 pulses to perform a
read operation and 70 pulses to perform a multiplication operation.
Programming Languages
-
8/2/2019 week1-intro323
23/34
ihs/CSCS323/Spring 2012 23
Programming Languages
Machine LanguageThe computer can execute a program written in machine language only.
In Machine Language, operations and operands are expressed in terms of 0s and 1s (bit
patterns).Example:
Instruction
00000101 00000100 00000000
Meaning
Add 4 to AX and store the result in AX
Disadvantage of machine language?
It is very difficult to write programs in machine language It is even more difficult to maintain (correct / modify) them.
What is solution then? Assembly Languages was invented in early 1950s
Programming Languages (contd )
-
8/2/2019 week1-intro323
24/34
ihs/CSCS323/Spring 2012 24
Programming Languages (contd.)
Assembly Language
The binary codes of operations were replaced by code words called mnemonics
Memory addresses were replaced by variables
Codes for registers were replaced by their names.
The above instruction written in assembly language becomes:
ADD AX, 4 Add 4 to AX and store the result in AX
Disadvantaes of Assembly language?
Instructions are very primitive; not suitable for writing large programs.
What is solution then?
High Level Languages (Fortran, Pascal, C, C++, Java, have been invented.
High Level languages
Ex. Point out distinguishing feature of High Level languages.
-
8/2/2019 week1-intro323
25/34
ihs/CSCS323/Spring 2012 25
Organization of the IBM PC
Intel introduced first 16 bit processor 8086 in 1978
The 8 bit 8088 processor was introduced in 1979.
The 8086 processor had faster clock and better performance
IBM selected 8088 to build PC because it was more economical
Both the processors had the same instruction set which forms the basicinstruction set for the subsequent processors.
Then Intel gradually introduced 80186, 80286, 80386, 80486, processors.
The subsequent processors usually had more facilities including faster
clock speed, bigger bus, bigger instruction set, etc.
EX.Highlight distinguishing features of 80186, 80286, 80386, 80486 processors.
-
8/2/2019 week1-intro323
26/34
ihs/CSCS323/Spring 2012 26
Organization of the 8086 Processor
The information inside the processor is stored in registers
The 8086 processor has 14 registers each of size 16 bit.
Type of registers:
Register FunctionData registers Contain data for operationsAddress registers Contain address of an instructionFlags register Contains status of the processor
-
8/2/2019 week1-intro323
27/34
ihs/CSCS323/Spring 2012 27
Data Registers AX, BX, CX, DX
These registers are available to the programmers for general use.
The processing of the instructions stored in the registers is faster than
those stored in the RAM.
Upper and lower halves of these registers can be used separately; e.g.
the upper half of AX is called AH and lower half is called AL and same
is true of the other registers.
In addition, these registers also perform the following special functions.
Data Registers AX BX CX DX
-
8/2/2019 week1-intro323
28/34
ihs/CSCS323/Spring 2012 28
Data Registers AX, BX, CX, DX
Register Special FunctionAX(Accumulator register) It is preferred to be used in arithmetic, logic and data transferinstructions because its use generates shortest machine code.
Also used in I/O and multiplication & division operations
BX(Base register)
Used as address register; e.g. in XLATE instruction.
CX(Counter register) Used as a counter in LOOP and REP (repeat) instructions andstring operations.
DX(Data register) used in Output, multiplication and division operations.
-
8/2/2019 week1-intro323
29/34
ihs/CSCS323/Spring 2012 29
Segment Registers CS, DS, SS, ES
The segment registers are used to store RAM addresses of instructions
and of data
The processor uses these addresses to access the memory locations.
The 8086 processor used 20 bit address to each byte in its 1 MB RAM;
these are called physical addresses.
The size of each segment register is 16 bit and cannot accommodate
20 bit address. What is solution?
o Divide the 20 bit physical address into two components and load
each component in a separate register.
o For this purpose main memory is divided into segments.
Segments
-
8/2/2019 week1-intro323
30/34
ihs/CSCS323/Spring 2012 30
Segments
What is a segment?
o A segment is a contiguous block of216 bytes (64 KB) of RAM so that the address
size of each of its bytes is 16 bit. The byte number within the segment is called
offset.
o Each segment is identified by a 16-bit segment number.
o Address of each byte has two parts:
1. segment number2. offset.
o This is called logical address and is written as:
Segment# : Offset
Example: 02AB : 0255H is a logical Address, where,
02AB is segment number,
0255 is offset
H indicates that these numbers are Hexadecimal.
Conversion of Logical Address into Physical Addresses
-
8/2/2019 week1-intro323
31/34
ihs/CSCS323/Spring 2012 31
Conversion of Logical Address into Physical Addresses
At the time of use, 2-dimensional logical address must be converted into
20-bit physical address because RAM has a 20-bit address associated
with each byte.
To do this:
1. Shift Segment # (expressed in Hex) by one position towards left,
2. Add offset (expressed in Hex) to it.
The physicaladdress corresponding to 02AB : 0255H is:
02AB0
+ 02 5 5
02D05
Conversion of Logical Address into Physical Addresses
-
8/2/2019 week1-intro323
32/34
ihs/CSCS323/Spring 2012 32
Conversion of Logical Address into Physical Addresses
Assignment # 1
Marks = 4 Last Date of Submission: 14 March 20121. Show that segments are overlapping.
2. What is minimum size of a segment and why?
3. How can the size of segment be increased?
4. What is maximum size of a segment and why?
-
8/2/2019 week1-intro323
33/34
ihs/CSCS323/Spring 2012 33
Segment Registers (Contd.)
The logical address consists of 16-bit segment number and a 16-bit offset.
The segment number is stored in a segment register (CS, DS, SS or ES).
The offset is stored in the companion of that segment register.
The following are companion registers.
Segment Register Companion register
CS IP ( Instruction pointer)
DS SI (Source Index)
SS SP (Stack Pointer)
BP ( Base Pointer)
ES DI ( destination Index)
-
8/2/2019 week1-intro323
34/34
ihs/CSCS323/Spring 2012 34
Flags Register
9 out of its 16 bits are used as flags.
Six bit (0, 2, 4, 6, 7 and 11) represent status flags
Three bits (8,9,10) represent control flags
Six status flags reflect the result of the preceding instruction; if result of
the preceding instruction is zero then the flag ZF is made 1 (true).
Three control flags enable or disable certain operations of the processor;
e.g. if the interrupt flag IF is made zero then the input from the
keyboard is ignored by the processor.