Organization ============== Unsigned binary, hex, and octal numbers Communication between the CPU and main memory: Data bus, address bus, R/~W line Application of info about numbers # addresses X bytes/address = size of memory (bytes) # addresses determined by size of address bus ========================================================= Unsigned binary, hex, and octal numbers --------------------------------------- Unsigned numbers: only positive numbers decimal numbers: base=10; digits are 0-9 meaning of, e.g., 2153_10: (2 * 10^3) + (1 * 10^2) + (5 * 10^1) + (3 * 10^0) binary numbers: base=2; digits are 0-1 meaning of, e.g., 1101_2: (1 * 2^3) + (1 * 2^2) + (0 * 2^1) + (1 * 2^0) = 13_10 octal numbers: base=8; digits are 0-7 meaning of, e.g., 153_8: (1 * 8^2) + (5 * 8^1) + (3 * 8^0) = 107_10 hexidecimal numbers: base=16; digits are ??? why can't we use 10, 11, 12, 13, 14, 15 as digist? how could you distinguish, e.g.: 15_16 = 21_10 from 15_16 = 15_10? you couldn't! so, we use: 0-9, A,B,C,D,E,F now: 15_16 = 21_10 and F_16 = 15_10 meaning of, e.g., 153_16: (1 * 16^2) + (5 * 16^1) + (3 * 16^0) = 339_10 converting between hex and binary ---------------------------------- 4 binary digits = 1 hex digits make sense? well, 2^4 = 16 conversion is easy! just be sure to always start at the right, and remember that the rightmost position is Base^0 (not Base^1) 10011000_2 = what in decimal? what in hex? = 2^7 + 2^4 + 2^3 = 128 + 16 + 8 = 152_10 = 98_16 = (9 * 16^1) + (8 * 16^0) = 144 + 8 = 152_10 72_16 = what in decimal? what in binary? = 7 * 16 + 2 = 114_10 = 0111 0010_2 = 2^6 + 2^5 + 2^4 + 2^1 = 114_10 range/how many numbers in N bits? ---------------------------------- How many binary numbers that can be represented in N bits? 2^N **warning -- that's N *BITS* Range of binary numbers that can be represented in N bits? 0 to (2^N)-1 e.g., 3 bits: 000, 001, 010, 011, 100, 101, 110, 111 e.g., 4 bits: 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111 trick for converting FF..F_16 into decimal -------------------------------------------- What decimal number is FF_16? there is a conversion table in the small manual Easier: what binary number is this? 1111 1111 What binary number is this 1 less than? 1111 1111 + 1 = 1 0000 0000 What number is this? Just count from the right, starting at 0! 1 0000 0000_2 = 2^8 = 256_10 so, 1111 1111_2 = 255_10 (128+64+32+16+8+4+2+1) since 1111 1111_2 = FF_16, FF_16 = 255_10. This will come in handy throughout the course. trick for converting from binary to decimal ------------------------------------------- Go to the nearest number you recognize, then add or subtract as appropriate. So, what is 1111 1110_2? We know 1111 1111_2 = 255_10, so subtract one from that to get 254_10 How about 1110 1110_2? 255 - 16 - 1 = 238_10 (But you can always use the conversion table in the manual) OK, now we can go on.... ===================================================== Communication between the CPU and main memory ----------------------------------------------- Buses: there are 3 types of signals, data, address, and control Data bus carries the actual data Address bus carries the address of the location being read from or written to Control bus contains signals that determine what the hardware does Clock creates a fixed-frequency signal that provides timing for the entire system See "Bus" diagram in lecture Address bus: unidirectional or bidirectional? Data bus: unidirectional or bidirectional? R/~W line: unidirectional or bidirectional? CPU/Memory operate in a ``Master-Slave" relationship (sketch in lecture) Bits are often grouped into "bytes"; 8 bits = 1 byte Also: 4 bit = 1 hex digit = "nybble" Application of what you learned earlier about binary numbers: ------------------------------------------------------------- How many addresses can there be if the address bus is N bits wide? 2^N What's the lowest and highest possible addresses (i.e., what's the range of addresses?) 0 to (2^N) - 1 ***The size of the address bus limits the number of addresses you can have What would you do if you have, e.g., an 8 bit address bus, but 2^9 bytes of memory? -- how many addresses can be represented in 8 bits? 2^8 -- we have 2^9 bytes of memory... 2^9 = 2 * (2^8) -- answer: give only every OTHER byte an address (see picture in lecture) Definition: the addressable unit (often also called a "word") is the number of bytes in the unit that is given an address if the address bus is N bits wide, and the addressable unit is A, then: 2^N addresses * (A bytes/address) = (2^N * A) total bytes of memory Aside: some standard units of measure kilobyte = 2^10 bytes = 1024 bytes megabyte = 2^10 kilobytes = 2^10 * 2^10 = 2^20 bytes gigabyte = 2^10 megabytes = 2^10 * 2^10 * 2^10 = 2^30 bytes Examples of calculating memory sizes: Maximum memory address = FFF_16 Addressable unit = 2 How many bytes is memory, in decimal? Number of addresses * 2 bytes/address Number of addresses? FFF_16 + 1 Note: expressing answer in powers of 2 is good; no reason to multiple answer out on exam What is FFF_16? Can look it up in the conversion table; or express it in binary and add up each digit; or use our trick FFF_16 = 1111 1111 1111_2 = 1 less than 1 0000 0000 0000_2 = (2^12 - 1)_10 And, there are 2^12 total addresses (000_16 to FFF_16) So, the size of memory is: 2^12 addresses * 2 bytes/address = 2^13 bytes = 8192 bytes How many kilobytes is this? 2^13 bytes * 1 kilobyte / 2^10 bytes = (2^13 / 2^10) bytes = 8 kilobytes -------------- Let's check the answer: FFF_16 = (2^12 -1)_10 = 4096 - 1 = 4095_10 table in the manual: 3840 + 240 + 15 = 4095 or, what is FFF_16 1 less than? 1000_16 = 1000_16 = 16^3 = 4096_10 so, FFF_16 = 4095_10 ---------------- Another example (see diagram "Bus" drawn in lecture): How many address lines and how many data lines are needed for 128K word X 20-bit memory? What does this mean? Word=addressable unit; each word is 20 bits. 128K word means that there are 128K units with addresses. This is 2^7 * 2^10 = 2^17 addresses So, the address bus must be 17 bits wide Data bus must be 20 bits wide, since 20 bits will be transferred at once