Lecture 1 Comp Sys
Lecture 1 Comp Sys
Programming
Dr. Abdullah Waqas
Introduction
• Binary numbers
• All computers work with 0’s and 1’s so it is like learning alphabets before
learning English
• Base conversion
• For convenience, people use other bases (like decimal, hexdecimal) and we need
to know how to convert from one to another.
• Number systems
• There are more than one way to express a number in binary. So 1010 could be -
2, -5 or -6 and need to know which one.
• A/D and D/A conversion
• Real world signals come in continuous/analog format and it is good to know
generally how they become 0’s and 1’s (and visa versa).
Digital
• Digital = discrete
Decimal BCD
• Binary codes (example: BCD)
Symbols Code
• Decimal digits 0-9
0 0000
1 0001
• Binary codes 2 0010
• Represent symbols using binary digits 3 0011
(bits)
4 0100
• Digital computers: 5 0101
• I/O is digital 6 0110
• ASCII, decimal, etc. 7 0111
• Internal representation is binary 8 1000
• Process information in bits 9 1001
The basics: Binary numbers
• Historically: 3 approaches
• Sign-and-magnitude
• Ones-complement
• Twos-complement
–3 1110 0001 +2
Only one zero! 1101 0010
–4 +3
1100 0011
MSB is the sign digit
0 ≡ positive – 5 1011 0100 + 4
1010 0101
1 ≡ negative
–6 1001 0110 +5
–7 1000 0111 +6
–8 +7
Twos-complement (con’t)
• Complementing a complement the original number
• Arithmetic is easy
• Subtraction = negation and addition
• Easy to implement in hardware
Miscellaneous
• Twos-complement of non-integers
• 1.687510 = 01.10112
• –1.687510 = 10.01012
• Sign extension
• Write +6 and –6 as twos complement
• 0110 and 1010
• Sign extend to 8-bit bytes
• 00000110 and 11111010
–1 0 –1 0
–2 1111 0000 + 1 –2 1111 0000 + 1
–3 1110 0001 + 2 –3 1110 0001 + 2
1101 0010 1101 0010
– 4 1100 0011 + 3 – 4 1100 0011 + 3
– 5 1011 0100 + 4 – 5 1011 0100 + 4
1010 0101 1010 0101
• Make sure to have enough bits to handle overflow
–6 1001 0110 + 5 –6 1001 0110 + 5
–7 1000 0111 + 6 –7 1000 0111 + 6
–8 +7 –8 +7
6 + 4 ⇒ –6 –7 – 3 ⇒ +6
Gray and BCD codes
• Quantizing a signal
• We sample it
Address Bus
Data Bus Memory
CPU
Control Bus Subsystem
I/O Device
Subsystem 20
Each of these Components are connected
through Buses.
• BUS - Physically a set of wires. The components of the Computer are
connected to these buses.
• Address Bus
• Data Bus
• Control Bus
21
Address Bus
22
Data Bus
23
Control Bus
24
I/O Bus or Local Bus
• In today’s computers the the I/O controller will have an extra bus
called the I/O bus.
• The I/O bus will be used to access all other I/O devices connected to
the system.
• Example: PCI bus
25
Instruction Cycles
26
CPU organization
27
Register Section
28
Arithmetic/Logic Unit (ALU)
29
MEMORY ORGANIZATION
• Memory Hierarchy
• Main Memory
• Auxiliary Memory
• Associative Memory
• Cache Memory
• Virtual Memory
30
Memory
Main memory consists of a number of
storage locations, each of which is
identified by a unique address
The ability of the CPU to identify each
location is known as its addressability
31
Memory Hierarchy
MEMORY HIERARCHY
CPU Cache
memory
Register
Cache
Main Memory
Magnetic Disk
Magnetic Tape
32
Memory Subsystem
• 2 Types of Memory:
• ROM : Read Only Memory
• Program that is loaded into memory and cannot be changed also retains its data even
without power.
• RAM : Random Access Memory
• Also called read/write memory. This type of memory can have a program loaded and
then reloaded. It also loses its data with no power.
33
Different ROM Chips
• Masked ROM :
• ROM that is programmed with data when fabricated. Data will not change once
installed. Hardwired.
• EEPROM :
• Another form of EPROM but is reprogammable electrically.
34
Different RAM Chips
35
The operation of cache memory
Cache
Main
Memory CPU
Memory
(SRAM)
(DRAM)
3. If it is, then the
4. If not, the CPU has to
instruction is fetched from
fetch next instruction from
the cache – a very fast
main memory - a much
position
slower process
= Bus connections
36
Addressing Modes
• Immediate
• Direct
• Indirect
• Register
• Register Indirect
• Displacement (Indexed)
• Stack
37
Immediate Addressing
38
Immediate Addressing Diagram
Instruction
Opcode Operand
39
Direct Addressing
• Address field contains address of operand
• Effective address (EA) = address field (A)
• e.g. ADD A
• Add contents of cell A to accumulator
• Look in memory at address A for operand
• Single memory reference to access data
• No additional calculations to work out effective address
• Limited address space
40
Direct Addressing Diagram
Instruction
Opcode Address A
Memory
Operand
41
Direct Addressing Diagram
Instruction
Opcode Address A
Memory
Operand
42
Indirect Addressing (1)
43
Indirect Addressing (2)
44
Indirect Addressing Diagram
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
45
Register Addressing (1)
46
Register Addressing (2)
• No memory access
• Very fast execution
• Very limited address space
• Multiple registers helps performance
• Requires good assembly programming or compiler writing
• N.B. C programming
• register int a;
• c.f. Direct addressing
47
Register Addressing Diagram
Instruction
Opcode Register Address R
Registers
Operand
48
Register Indirect Addressing
49
Register Indirect Addressing Diagram
Instruction
Opcode Register Address R
Memory
Registers
50
Displacement Addressing
• EA = A + (R)
• Address field hold two values
• A = base value
• R = register that holds displacement
• or vice versa
51
Displacement Addressing Diagram
Instruction
Opcode Register R Address A
Memory
Registers
52
Relative Addressing
53
Base-Register Addressing
• A holds displacement
• R holds pointer to base address
• R may be explicit or implicit
• e.g. segment registers in 80x86
54
Indexed Addressing
• A = base
• R = displacement
• EA = A + (R)
• Good for accessing arrays
• EA = A + (R)
• R++
55
Stack Addressing
56
Input-Output Organization
57
• 2) A synchronization mechanism may be needed
• The data transfer rate of peripherals is usually slower than the transfer rate of the CPU
• 3) Data codes and formats in peripherals differ from the word format in the CPU and Memory
• 4) The operating modes of peripherals are different from each other
• Each peripherals must be controlled so as not to disturb the operation of other peripherals connected to the CPU
• Interface
• Special hardware components between the CPU and peripherals
• Supervise and Synchronize all input and output transfers
I/O bus
D ata
P rocessor A ddress
C ontrol
Keyboard
and
display
P rinter
M agnetic
disk
M agnetic
tape
58
term inal
• Transfer
• Synchronous Data Transfer
• All data transfers occur simultaneously during the
occurrence of a clock pulse
• Registers in the interface share a common clock with CPU
registers
• Asynchronous Data Transfer
• Internal timing in each unit (CPU and Interface) is
independent
• Each unit uses its own private clock for internal registers
59
Data bus Data bus
Source Destination Source Destination
unit Strobe unit unit Strobe unit
Strobe Strobe
(b) Timing diagram (b) Timing diagram
60
D ata bus Data bus
D ata
Valid data
61
• 11-4 Modes of Transfer
Read status register
• Data transfer to and from peripherals
• 1) Programmed I/O Check flag bit
• 2) Interrupt-initiated I/O
• 3) Direct Memory Access (DMA) = 0
F la g
yes
Continue
w ith
program
62
• Polling
• Identify the highest-priority source by software means
• One common branch address is used for all interrupts
• Program polls the interrupt sources in sequence
• The highest-priority source is tested first
• Polling priority interrupt
• If there are many interrupt sources, the time required to poll them can exceed the time
available to service the I/O device
• 따라서 Hardware priority interrupt
• Daisy-Chaining :
“1 “1 “0
To next
PI PO PI PO PI PO
D evice
” ” ”
Interrupt request
IN T
CPU
Interrupt acknow ledge
IN TA C K
63
VA D
INTACK P riority in
Enable
PI
Vector address
64
• Direct Memory Access (DMA)
• DMA
• DMA controller takes over the buses to manage the transfer directly between the I/O
device and memory
65
• Transfer Modes
• 1) Burst transfer :
• 2) Cycle stealing transfer Address bus
• DMA Controller ( Intel 8237 DMAC )
• DMA Initialization Process
• 1) Set Address register :
• memory address for read/write Data bus Address bus
Data bus buffers
• 2) Set Word count register : buffers
• the number of words to transfer
• 3) Set transfer mode :
4) DMA transfer start :
• 5) EOT (End of Transfer) :
DMA select CS Address register
Internal bus
Register select RS
Read RD Word count register
Write WR
Control
Bus request BR logic Control register
Bus grant BG
DMA request
Interrupt Interrupt
to I/O device
DMA Acknowledge
66
• DMA Transfer (I/O to Memory)
• 1) I/O Device sends a DMA request
• 2) DMAC activates the BR line
• 3) CPU responds with BG line
• 4) DMAC sends a DMA acknowledge
Interrupt
to the I/O device BG Random access
CPU
• 5) I/O device puts a word in the data BR
memory (RAM)
RD WR Address Data
DMA acknowledge
DS
RS Direct memory I/O
access (DAM) Peripheral
BR controller device
DMA request
BG
Interrupt
67
• Input-Output Processor (IOP)
• IOP
• Communicate directly with all I/O devices
• Fetch and execute its own instruction
• IOP instructions are specifically designed to facilitate I/O transfer
• DMAC must be set up entirely by the CPU
• Designed to handle the details of I/O processing
Central Processing
unit (CPU)
Memory bus
Peripheral devices
Mem ory unit PD PD PD PD
Input-output
processor (IOP) I/O bus
68
• CPU - IOP Communication
• Memory units acts as a message center :
• each processor leaves information for the other
Send instruction
Transfer status w ord
to test IO P path
to m em ory location
If status O K. , send
start I/O instruction Access m em ory for
to IO P IO P program
Request IO P status
Continue
69
Input/output Devices
70
Input Devices are:
• Keyboard
• Mouse
• Joystick
• Scanner
• Light Pen
• Touch Screen
71
\
72
Intel 8086/8088 Microprocessors
• Intel 8086 and 8088 Microprocessors are the basis of all IBM-PC
compatible computers
(8086 introduced in 1978, first IBM-PC released in 1981)
• All Intel, AMD and other advanced microprocessors are based on and
are compatible with the original 8086/8
• At Power Up and Reset time, Pentiums, Athlons etc all look like 8086
processors
73
Intel 8086/8088 Microprocessors
75
8086/8088 Functional Units
Bus Interface
Unit(BIU)
Execution Unit
Fetches Opcodes,
(EU)
Reads Operands,
Writes Data
8086/8088 MPU
76
8086/8088
77
8086/8088 Internal OrganisationEU BIU
AH AL SUMMATION
BH BL
Data Bus
CH CL
CS
DH DL
DS
SP
SS
BP
ES
DI
IO
BI
Internal Bus
Communications Control
Registers
8088
Bus
Temporary
Registers
Instruction Queue
ALU
EU
Control
1 2 3 4
Flags
78
BIU Elements
• Instruction Queue: the next instructions or data can be
fetched from memory while the processor is executing the
current instruction
• The memory interface is slower than the processor execution time so
this speeds up overall performance
• Segment Registers:
• CS, DS, SS and ES are 16b registers
• Used with the 16b Base registers to generate the 20b address
• Allow the 8086/8088 to address 1MB of memory
• Changed under program control to point to different segments as a
program executes
• Instruction Pointer (IP) contains the Offset Address of the next
instruction, the distance in bytes from the address given by
the current CS register
79
8086/8088 20-bit Addresses
CS
IP
80
BIU Elements
• Instruction Queue: the next instructions or data can be
fetched from memory while the processor is executing the
current instruction
• The memory interface is slower than the processor execution time so
this speeds up overall performance
• Segment Registers:
• CS, DS, SS and ES are 16b registers
• Used with the 16b Base registers to generate the 20b address
• Allow the 8086/8088 to address 1MB of memory
• Changed under program control to point to different segments as a
program executes
• Instruction Pointer (IP) contains the Offset Address of the next
instruction, the distance in bytes from the address given by
the current CS register
81
MAXIMUM MINIMUM
MODE MODE
GND 1 40 Vcc
AD14 AD15
AD13 A16,S3
AD12 A17,S4
AD11 A18,S5
AD10 A19,S6
AD9 /BHE,S7
AD8 MN,/MX
AD7 /RD
AD6 /RQ,/GT0 HOLD
AD5
8086 /RQ,/GT1 HLDA
AD4 /LOCK /WR
AD3 /S2 IO/M
AD2 /S1 DT/R
AD1 /S0 /DEN
AD0 QS0 ALE
NMI QS1 /INTA
INTR /TEST
CLK READY
GND 20 21 RESET
82
8086/8088 Summary
83
• Thanks
84