Random access memory •• SSequenttiiall ciircuiittss allll ddeppendd uppon tthhe ppressence off mmemmory. – A flip-flop can store one bit of information. – A register can store a single “word,” typically 32-64 bits. •• RRanddom access memory, or RRAAMM, allllows us tto sttore even llarger amountts of data. Today we’ll see: – The basic interface to memory. –– HHooww yyoouu ccaann iimmpplleemmeenntt ssttaattiicc RRAAMM cchhiippss hhiieerraarrcchhiiccaallllyy. • This is the last piece we need to put together a computer! Random Access Memory 1 Introduction to RAM •• RRanddomm-accessss mmemmory, or RRAAMM, pproviiddess llarge quanttiittiiess off ttemmpporary storage in a computer system. • Remember the basic capabilities of a memory: – IItt sshhoouulldd bbee aabbllee ttoo ssttoorree aa vvaalluuee. – You should be able to read the value that was saved. – You should be able to change the stored value. •• AA RRAAMM iiss ssiimmiillaarr, eexxcceepptt tthhaatt iitt ccaann ssttoorree mmaannyyvvaalluueess. – An address will specify which memory value we’re interested in. – Each value can be a multiple-bit word (e.g., 32 bits). •• WWee’llll rreeffiinnee tthhee mmeemmoorryy pprrooppeerrttiieess aass ffoolllloowwss:: A RAM should be able to: - SSttorree mmaannyy wworrddss, onnee ppeerr aaddddrreessss - Read the word that was saved at a particular address - Change the word that’s saved at a particular address Random Access Memory 2 Picture of memory •• YYou can tthhiinkk off commpputter mmemmory ass bbeiing one AAddddrreessss DDaattaa big array of data. 00000000 – The address serves as an array index. 00000001 – 0000000000000022 EEaacchh aaddddrreessss rreeffeerrss ttoo oonnee wwoorrdd ooff ddaattaa. • . You can read or modify the data at any given . memory address, just like you can read or modifyy the contents of an arrayy at anyy ggiven . index. . • If you’ve worked with pointers in C or C++, then . you’ve already worked with memory addresses. . . . . . FFFFFFFD FFFFFFFE FFFFFFFFFFFFFFFF Random Access Memory 3 Block diagram of RAM 2k x n memory CS WR Memory operation k n ADDRRSS OOUUT 0 x None n DATA 1 0 Read selected word CS 1 1 Write selected word WR • This block diagram introduces the main interface to RAM. – A Chip Select, CS, enables or disables the RAM. – AADDRRSS speciiffiies tthhe addddress or llocattiion tto readd ffrom or wriitte tto. – WR selects between reading from or writing to the memory. To read from memory, WR should be set to 0. OOUUTT wwiillll bbee tthhee nn-bbiitt vvaalluuee ssttoorreedd aatt AADDRRSS. To write to memory, we set WR = 1. DATA is the n-bit value to save in memory. • TThhiiss iinntteerrffaaccee mmaakkeess iitt eeaassyy ttoo ccoommbbiinnee RRAAMMss ttooggeetthheerr, aass wwee’llll sseeee. Random Access Memory 4 Memory sizes •• WWe reffer tto tthhiiss ass a 22kk xx n mmemmory. – There are k address lines, which can specify one of 2k addresses. – Each address contains an n-bit word. 2k x n memory kk nn AADDRRSS OOUUTT n DATA CS WWRR • For example, a 224 x 16 RAM contains 224 = 16M words, each 16 bits long. – TThhe RRAAMM woulldd needd 2244 addddress lliines. – The total storage capacity is 224 x 16 = 228 bits. Random Access Memory 5 Size matters! •• MMemmory ssiizess are ussualllly ssppeciiffiiedd iin nummbberss off bbyttess ((88 bbiittss)). • The 228-bit memory on the previous page translates into: 228 bits / 8 bits pper byyte = 225 byytes • With the abbreviations below, this is equivalent to 32 megabytes. Prefix Base 2 Base 10 10 3 K Kilo 2 = 1,024 10 = 1,000 20 6 M Mega 2 = 1,048,576 10 = 1,000,000 30 9 GG GGiiggaa 22 == 11,007733,774411,882244 1100 == 11,000000,000000,000000 • To confuse you, RAM size is measured in base 2 units, while hard drive ssiizzee iiss mmeeaassuurreedd iinn bbaassee 1100 uunniittss. – In this class, we’ll only concern ourselves with the base 2 units. Random Access Memory 6 Typical memory sizes •• SSomme ttyppiicall mmemmory cappaciittiiess:: AAddddrreessss DDaattaa – 00000000 PCs usually come with 512MB – 2GB RAM. – 00000001 PDAs have 16-64MB of memory. 0000000000000022 – DDiigiittall cameras andd MMPP33 pllayers can hhave . 32MB-8GB or more of onboard storage. . • Many operating systems implement virtual . mmeemmoorryy, wwhhiicchh mmaakkeess tthhee mmeemmoorryy sseeeemm llaarrggeerr . than it really is. – . Most systems allow up to 32-bit addresses. This works out to 232, or about four billion, . different possible addresses. . – . With a data size of one byte, the result is apparently a 4GB memory! . – . TThhe operattiing systtem uses hhardd ddiiskk space as a substitute for “real” memory. FFFFFFFD FFFFFFFE FFFFFFFFFFFFFFFF Random Access Memory 7 Reading RAM •• TTo readdffromm tthhiiss RRAAMM, tthhe conttrolllliing ciircuiitt mmusstt:: – Enable the chip by ensuring CS = 1. – Select the read operation, by setting WR = 0. – SSendd tthhe ddesiiredd addddress tto tthhe AADDRRSS iinputt. – The contents of that address appear on OUT after a little while. • Notice that the DATA input is unused for read operations. 2k x n memory k n ADRS OUT n DATA CCSS WR Random Access Memory 8 Writing RAM •• TTo wriittetto tthhiiss RRAAMM, you needd tto:: – Enable the chip by setting CS = 1. – Select the write operation, by setting WR = 1. – SSendd tthhe ddesiiredd addddress tto tthhe AADDRRSS iinputt. – Send the word to store to the DATA input. • The output OUT is not needed for memory write operations. 2k x n memory k n ADRS OUT n DATA CCSS WR Random Access Memory 9 Static memory •• HHow can you iimmppllemmentt tthhe mmemmory chhiipp?? • There are many different kinds of RAM. – We’ll start off discussing static memory, which is most commonly uusseedd iinn ccaacchheess aanndd vviiddeeoo ccaarrddss. – Later we mention a little about dynamic memory, which forms the bulk of a computer’s main memory. • SSttaattiicc mmeemmoorryy iiss mmooddeelleedd uussiinngg oonnee llaattcchhffoorr eeaacchh bbiitt ooff ssttoorraaggee. • Why use latches instead of flip flops? – A latch can be made with only two NAND or two NOR gates, but a fflipp-fflopp reqquires at least twice that much hardware. – In general, smaller is faster, cheaper and requires less power. – The tradeoff is that getting the timing exactly right is a pain. Random Access Memory 10
Description: