Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CSCS 323: Course Title Course Code Credits Instructor

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 34

CSCS 323

Course Title Course Code


Computer Organization with Assembly Language COMP 323 3 Dr. Iftikhar Hussain Shah

Credits
Instructor

Recommended Books / Material

Assembly Language Programming and Organization of the IBM PC by Ytha Yu and Charles Marut (McGraw-Hill)

ihs/CSCS323/Spring 2012

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.

2.

Hardware It consists of circuits which can read, store, retrieve, process and display information. Software It consists of programs which:
a. b.

drive the computer (Operating System) facilitate users to perform specific jobs such as word processing
(Application Software).

ihs/CSCS323/Spring 2012

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 Decimal Binary Octal Hexadecimal Digits 0-9 0,1 (bits) 0-7 0-9, A-F (A=10, F=15) Base 10 2 8 16

ihs/CSCS323/Spring 2012

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 binary equivalent of that decimal number. Example: The binary equivalent of 23 is calculated below.
2 23

2
2 2 2 2

11 1
5 1 2 1 1 0 0 1
Base

(23)10 = (10111)2

ihs/CSCS323/Spring 2012

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 decimal equivalent of the given binary number.

Example:
(10111)2 = 1*20 + 1*21 + 1*22 + 0*23 + 1*24 = (23)10

ihs/CSCS323/Spring 2012

Representation of Numbers
(10111)2 is 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.

ihs/CSCS323/Spring 2012

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 the hexadecimal equivalent of that decimal number. Example1: The hex. equivalent of 37 is calculated below.
16 16 37 25

(37)10 = (25)16

02

Ex.1. Show that (140)10 = (8C)16


Ex.2. Compute hex. Equivalents of the following decimal numbers: 16, 32, 255, 256, 2047
ihs/CSCS323/Spring 2012 7

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 gives the decimal equivalent of the given binary number. Example: (25)2 = 5*160 + 2*161 = (37)10

Ex. Write down a general rules for converting


a decimal number to an equivalent number in any other system and vice versa.

ihs/CSCS323/Spring 2012

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-bit binary 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 and check the result: 0A7Dh, 48GDh

ihs/CSCS323/Spring 2012

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 bits of the given binary number. If the last group does not contain 4 bits place required 0s to its left. Then replace each group of four bits by it hexadecimal equivalent. Examples: 100101b = 00100101b = 25h
2

10001100b = 8Ch EX. Convert the following hex. numbers to their binary equivalents and check the result: 0A7Dh, 48GDh

ihs/CSCS323/Spring 2012

10

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

ihs/CSCS323/Spring 2012

11

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.

ihs/CSCS323/Spring 2012

12

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).

ihs/CSCS323/Spring 2012

13

Exercise
How is information represented inside the computer. Write a detailed note on different coding Systems.

ihs/CSCS323/Spring 2012

14

Example (ASCII CODES)

ihs/CSCS323/Spring 2012

15

Logic instructions
o o Logic instructions can be used to change individual bits in the computer 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 AND b

a OR b

a XOR b

0
0 1 1

0
1 0 1
a 0 1

0
0 0 1
NOT a 1 0

0
1 1 1

0
1 1 0

ihs/CSCS323/Spring 2012

16

Logic instructions (continued)


o o Logic instructions can be used to change individual bits in the computer 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 F F

b F T

a AND b F F

a OR b F T

a XOR b F T

T
T

F
T

F
T

T
T

T
F

a F T

NOT a T F
ihs/CSCS323/Spring 2012 17

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.

ihs/CSCS323/Spring 2012

18

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.

ihs/CSCS323/Spring 2012

19

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.

ihs/CSCS323/Spring 2012

20

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: a. Opcode : specifies type of operation Operands : are usually registers or memory addresses Fetch-Execute Cycle Fetch b. Bring instructions from the main memory Decode the instruction into an operation Fetch data from the main memory

Execute

Perform the operation on data


Store result back into the main memory if required

ihs/CSCS323/Spring 2012

21

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.

<----Period---->

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.

ihs/CSCS323/Spring 2012

22

Programming Languages
Machine Language
The 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

ihs/CSCS323/Spring 2012

23

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.

ihs/CSCS323/Spring 2012

24

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 basic instruction 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.

ihs/CSCS323/Spring 2012

25

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 Data registers Address registers

Function Contain data for operations Contain address of an instruction

Flags register

Contains status of the processor

ihs/CSCS323/Spring 2012

26

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.

ihs/CSCS323/Spring 2012

27

Data Registers AX, BX, CX, DX


Register
AX (Accumulator register)

Special Function
It is preferred to be used in arithmetic, logic and data transfer instructions because its use generates shortest machine code. Also used in I/O and multiplication & division operations Used as address register; e.g. in XLATE instruction. Used as a counter in LOOP and REP (repeat) instructions and string operations.

BX (Base register) CX (Counter register)

DX (Data register)

used in Output, multiplication and division operations.

ihs/CSCS323/Spring 2012

28

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 o Divide the 20 bit physical address into two components and load each component in a separate register. For this purpose main memory is divided into segments.

ihs/CSCS323/Spring 2012

29

Segments
What is a segment?
o A segment is a contiguous block of 216 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. Each segment is identified by a 16-bit segment number. Address of each byte has two parts: 1. segment number 2. offset.

o 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.
ihs/CSCS323/Spring 2012 30

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 physical address corresponding to 02AB : 0255H is: 02AB0 + 02 5 5 02D05

ihs/CSCS323/Spring 2012

31

Conversion of Logical Address into Physical Addresses


Assignment # 1 Marks = 4 1. 2. 3. 4. Last Date of Submission: 14 March 2012

Show that segments are overlapping. What is minimum size of a segment and why? How can the size of segment be increased? What is maximum size of a segment and why?

ihs/CSCS323/Spring 2012

32

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
IP ( Instruction pointer) SI (Source Index) SP (Stack Pointer) BP ( Base Pointer) DI ( destination Index)

CS DS SS ES

ihs/CSCS323/Spring 2012

33

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.

ihs/CSCS323/Spring 2012

34

You might also like