cse 351 section 2
play

CSE 351 Section 2 1/12/12 Agenda Review memory and data - PowerPoint PPT Presentation

CSE 351 Section 2 1/12/12 Agenda Review memory and data representation NAND Gate Binary/Decimal/Hex Memory Organization and Pointers Endianness NAND Gate Output is always high (1) except when both inputs are high


  1. CSE 351 Section 2 1/12/12

  2. Agenda • Review memory and data representation – NAND Gate – Binary/Decimal/Hex – Memory Organization and Pointers – Endianness

  3. NAND Gate • Output is always high (1) except when both inputs are high – That is, the opposite of an AND • How does this circuit work? Truth Table

  4. NAND Gate • Output is always high (1) except when both inputs are high – That is, the opposite of an AND • How does this circuit work? Truth Table PNP Transistors “On” (behave like a wire) when input is low (0) NPN Transistors “On” (behave like a wire) when input is high (1)

  5. NAND Gate • Output is always high (1) except when both inputs are high – That is, the opposite of an AND • How does this circuit work? Truth Table 0 0 1 0 X 0 X

  6. NAND Gate • Output is always high (1) except when both inputs are high – That is, the opposite of an AND • How does this circuit work? Truth Table X 1 0 1 X 0 1

  7. NAND Gate • Output is always high (1) except when both inputs are high – That is, the opposite of an AND • How does this circuit work? Truth Table X 0 1 1 1 0 X

  8. NAND Gate • Output is always high (1) except when both inputs are high – That is, the opposite of an AND • How does this circuit work? Truth Table X 1 X 1 0 1 1

  9. Number Formats Decimal Binary • Hex Three bases programmers normally work in – Base 2: Binary 0 0 0000 – Base 10: Decimal 1 1 0001 2 2 0010 – Base 16: Hexadecimal 3 3 0011 • What do they mean? 4 4 0100 5 5 0101 – Each digit is a representation of the base raised to a power 6 6 0110 – Decimal: 246 10 = 2*10 2 + 4*10 1 + 6*10 0 7 7 0111 8 8 1000 – Binary: 11110110 2 = 1*2 7 + 1*2 6 + 1*2 5 + 1*2 4 + 0*2 3 + 1*2 2 + 9 9 1001 1*2 1 + 0*2 0 = 246 10 A 10 1010 – B 11 1011 Hex: F6 16 = 0xF6 = 15*16 1 + 6*16 0 = 246 10 C 12 1100 • Easy way to convert between Binary and Hex D 13 1101 E 14 1110 1. Divide binary number into chunks of 4 F 15 1111 2. Convert each chunk of 4 binary digits into a hex number e.g. 11110110 2 = 1111 0110 = F 6 = F6 16

  10. Memory Organization 64-bit 32-bit Bytes Addr. Words Words • Each memory address references a 0000 particular byte in memory Addr 0001 = • A 32-bit value (such as an int) is 4- 0002 ?? 0000 bytes long. Therefore, it takes Addr 0003 = up 4 memory addresses. 0004 ?? 0000 However, to reference this Addr 0005 = value, you look at the memory 0006 ?? 0004 address of the first byte. 0007 – 0008 E.g. If address 0004 holds an int, addresses 0004, 0005, 0006, Addr 0009 = 0007 hold that int. 0010 ?? 0008 Addr 0011 = 0012 ?? 0008 Addr 0013 = 0014 ?? 0012

  11. Byte Ordering Example • Big-Endian (PPC, Sparc, Internet) – Least significant byte has highest address • Little-Endian (x86) – Least significant byte has lowest address • Example – Variable has 4-byte representation 0x01234567 – Address of variable is 0x100 0x100 0x101 0x102 0x103 01 23 45 67 Big Endian 01 23 45 67 0x100 0x101 0x102 0x103 Little Endian 67 45 23 01 67 45 23 01 11

  12. Byte Ordering Example • Another way to visualize it Big Endian Little Endian 0x0FF 0x0FF 01 67 0x100 0x100 01 01 23 45 0x101 0x101 45 23 0x102 0x102 67 01 0x103 0x103 01 01 0x104 0x104 • Little Endian is Least significant byte first • Big Endian is Most significant byte first 12

  13. Representing Integers Decimal: 12345 • int A = 12345; Binary: 0011 0000 0011 1001 • int B = -12345; Hex: 3 0 3 9 • long int C = 12345; IA32, x86-64 A Sun A IA32 C X86-64 C Sun C 39 00 39 39 00 30 00 30 30 00 00 30 00 00 30 00 39 00 00 39 IA32, x86-64 B Sun B 00 00 C7 FF 00 CF FF 00 FF CF FF C7 Two’s complement representation for negative integers (covered later) 13

  14. Addresses and Pointers • Address is a location in memory • Pointer is a data object that contains an address 0000 • Address 0004 00 00 01 5F 0004 0008 stores the value 351 (or 15F 16 ) 000C 0010 • In C: 0014 0018 int x = 351; 001C //The compiler chooses to store x 0020 //at address 0004. Could really be anywhere. 0024 14

  15. Addresses and Pointers • Address is a location in memory • Pointer is a data object that contains an address • Address 0004 0000 stores the value 351 (or 15F 16 ) 00 00 01 5F 0004 • Pointer to address 0004 0008 stored at address 001C 000C • C: 0010 int x = 351; 0014 int * y = &x; //Pointer y is the address of x 0018 00 00 00 04 001C • That is, y points to where x is located 0020 • Compiler chooses to put the pointer y 0024 at address 001C 15

  16. Addresses and Pointers • Update the value of x by using the pointer • C: int x = 351; 0000 int* y = &x; 00 00 00 05 0004 *y = 5; 0008 000C • 0010 Read as “the value of the variable 0014 stored at the address in y gets 5”. 0018 This is the same as doing “x=5” 00 00 00 04 001C 0020 0024 16

  17. Addresses and Pointers • Pointer to a pointer in 0024 • C: int x = 351; 0000 00 00 00 05 0004 int* y = &x; 0008 *y = 5; 000C int** z = &y; 0010 0014 • Pointer z is stored at address 0024 0018 by the compiler. 00 00 00 04 001C • z points to y, and y points to x. 0020 • Could do “**z” to get 00 00 00 1C 0024 the value of x. 17

  18. Addresses and Pointers • What happens when you do y = y + 1? • C: int x = 351; 0000 int* y = &x; 00 00 00 05 0004 *y = 5; 0008 int** z = &y; 000C 0010 y = y + 1; 0014 0018 • y gets the previous address of x plus 00 00 00 08 001C 4 bytes (size of an int). 0020 • y no longer points to x 00 00 00 1C 0024 18

  19. HW 0 • http://www.cs.washington.edu/education/courses/cse351/12wi/homework-0.html Questions? What were your results?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend