Main Memory • Main memory – – a collection of storage locations, – each with a unique identifier called the address. • Word– Data are transferred to and from memory in groups of bits called words. – The number of bits that can be stored in one CPU register in a computer. Figure 5-3 Main memory Address Space • Although programmers use a name to identify a word, at the hardware level, each word is identified by an address. • Address space – The total number of uniquely identifiable locations in memory. – For example: a memory with 64KB and a word size of 1 byte has an address space that range from 0 to 65535. Table 5.1 Memory units Unit -----------KB-kilobyte MB-megabyte GB-gigabyte TB-terabyte PB-petabyte EB-exabyte Exact Number of bytes Approximation -----------------------210 bytes 220 bytes 230 bytes 240 bytes 250 bytes 260 bytes -----------103 bytes 106 bytes 109 bytes 1012 bytes 1015 bytes 1018 bytes Address as Bit Pattern • Because computers operate by storing numbers as bit patterns, the address itself is also represented as a bit pattern. • If a computer has N words of memory, you need an unsigned integer of size log2N bits to refer to each memory location. Note: Memory addresses are defined using unsigned binary integers. Example 1 A computer has 32 MB (megabytes) of memory. How many bits are needed to address any single byte in memory? Solution The memory address space is 32 MB, or 225 (25 x 220). This means you need log2 225 or 25 bits, to address each byte. Example 2 A computer has 128 MB of memory. Each word in this computer is 8 bytes. How many bits are needed to address any single word in memory? Solution The memory address space is 128 MB, which means 227. However, each word is 8 (23) bytes, which means that you have 224 words. This means you need log2 224 or 24 bits, to address each word. Memory Types • RAM (Random Access Memory) – Volatile – R/W by user – Two categories: • DRAM(Dynamic RAM) – Refresh – used in most PCs • SRAM(Static RAM) – No refresh – faster 、more reliable – more expensive – often used only as a memory cache Memory Types • ROM (Read Only Memory) – Nonvolatile – Written by manufacture – Hold the booting program – Categories: • ROM • PROM(Programmable ROM)- Write once by user • EPROM(Erasable PROM)- physical removal and reinstallation by special device • EEPROM(Electronically EPROM)- without being removed from computer Figure 5-4 Memory hierarchy Speed Secondary Memory Cost Space Cache Memory • Cache memory at any time contains a copy of a portion of main memory. 1. CPU checks the cache 2. If exist, copy the word, otherwise 1) access main memory and copy a block of memory starting with the desired word. 2) CPU accesses cache and copies the word. Figure 5-5 Cache • It is very probable that the CPU, in next cycle, needs to access the words following the first word. • The existence of the cache speeds processing. • 80-20 rule Most computers typically spend 80% of the time accessing only 20% of the data. • Same data are accessed over and over again. Input/Output Subsystem • I/O subsystem allows a computer to – Communicate with the outside world – Store programs and data even when the power is off. Nonstorage devices • allows the CPU/memory to communicate with the outside world • Keyboard – provides input • Monitor – display output – Echoes the input typed on the keyboard • Printer Storage devices • can store large amount of information to be retrieved at a later time. • Cheaper than main memory • Nonvolatile • Auxiliary storage device (Secondary memory) • Categories: – Magnetic – optical Magnetic Storage devices • Use magnetization to store bits of data • If a spot is magnetized 1 • If a spot is not magnetized 0 • Magnetic Disk – Random access device • Magnetic Tape – Sequential access device Physical layout of a magnetic disk • Performance depends on several factors Rotational speed Seek time – the time to move the R/W head to desired track Transfer time – the time to move data from the disk to the CPU/Memory Figure 5-6 Surface organization of a disk • Each surface is divided into tracks • Each track is divided into sectors • Sectorthe smallest storage area that can be accessed at one time. • Blockcan be stored in one or more sectors and retrieved together. Figure 5-7 Figure 5-8 Mechanical configuration of a tape • • • • Surface organization of a tape Sequential access Slower Cheaper Backup large amount of data • 9 vertical spots 8 bits of information 1 bit for error detection Figure 5-9 Optical Storage devices • Use light (laser) to store and retrieve data. • CD-ROM(Compact disc read-only memory) – Same technology as CD • CD-R (Compact disc recordable) – WORM(Write Once, Read Many) • CD-RW (Compact disc rewritable) – Also called Erasable optical disc • DVD(Digital Versatile Disc) – Higher capacity Memory hierarchy Speed Secondary Memory • Hard disk • Floppy disk (Diskette) •Flash memory • CD-R/CD-RW/DVD • Magnetic tape Cost Space Connecting CPU and memory using three buses • Data bus# of wires depends on the size of the word. • Address bus# of wires depends on the address space of memory. • Control bus# of wires depends on the total number of control commands a computer needs. Figure 5-14 Connecting I/O devices • The CPU and memory are electronic devices. • The I/O devices are eletromechanical, magnetic, or optical devices. – Much slower speed – Need for an intermediary- I/O controller (or interface) • Serial controlleronly one wire connection to the device • Parallel controllerseveral connections to the device Figure 5-15 Connecting I/O devices to the buses SCSI controller • SCSI(Small Computer System Interface) Parallel (8/16/32 bits) Daisy chained connection Unique ID for each device Figure 5-16 FireWire controller • IEEE 1394 (iLink) serial High speed up to 50MB/sec (400Mbps) Daisy-chain/Tree connection 1394b (800Mbps) Figure 5-17 USB controller • USB(Universal Serial Bus) serial 1.0 (12 Mbps) 2.0 (480 Mbps) Figure 5-18 Addressing I/O devices • The CPU use the same bus to R/W memory and I/O devices. The only difference is the instruction. • Two methods to handle the addressing of I/O devices – Isolated I/O – Memory-Mapped I/O Isolated I/O addressing • Different instructions • The I/O addresses can overlap with memory addresses without any ambiguity because the instruction itself is different. Figure 5-19 Memory-mapped I/O addressing • Same instructions • The CPU treats each register in the I/O controller as a word in memory. • Adv. – smaller # of instructions • Disadv. – part of the address space allocated for I/O Figure 5-20 Program Execution • • • • General–purpose computers use a set of instructions called a program to process data. Both the program and the data are stored in memory. The CPU uses repeating machine cycles to execute instructions in the program, one by one. A simplified cycle consists of: 1. Fetch 2. Decode 3. Execute Figure 5-21 Steps of a cycle