1 / 62

MEMORY ARCHITECTURE

MEMORY ARCHITECTURE. EEN 417 Fall 2013. MEMORY ARCHITECTURES. Thinking about memory. Imagine we have an 8-bit processor Has byte addressable memory 128B of RAM Imagine this processor has an instruction: LD, R, ADR Loads data from <ADR> to named register. Thinking about memory.

Download Presentation

MEMORY ARCHITECTURE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MEMORY ARCHITECTURE EEN 417 Fall 2013

  2. MEMORY ARCHITECTURES

  3. Thinking about memory • Imagine we have an 8-bit processor • Has byte addressable memory • 128B of RAM • Imagine this processor has an instruction: • LD, R, ADRLoads data from <ADR> to named register

  4. Thinking about memory • What would the following instruction do? • LD, R0, 0xFF • What will the result in R0 be?

  5. Thinking about memory • What will the result in R0 be? • Undefined -- Three possibilities: • Throw some sort of exception • Return the contents of 0x7F • Return a byte of 0x00 • Could be designed for any of these three

  6. An Exception? • Would be returned by a memory management unit (if one exists) • Sees the illegal address, and does… what?

  7. An Exception? • Would be returned by a memory management unit (if one exists) • Sees the illegal address, and does… what? • Set some bit in a status register?

  8. An Exception? • Would be returned by a memory management unit (if one exists) • Sees the illegal address, and does… what? • Set some bit in a status register? • Request an interrupt?

  9. An Exception? • Would be returned by a memory management unit (if one exists) • Sees the illegal address, and does… what? • Set some bit in a status register? • Request an interrupt? • What is an interrupt?

  10. Types of memory Stack Caches Scratchpad memories Absolute and relative addresses Virtual memory Heaps allocation/deallocation fragmentation garbage collection Segmented memory spaces … Memory Architecture: Issues These issues loom larger in embedded systems than in general-purpose computing.

  11. What do you think the difference is? • Register vs. DRAM? • Register vs. disk?

  12. What do you think the difference is? • Register vs. DRAM? • 100x slower • Register vs. disk? • 10,000x slower!!!

  13. What do you think the difference is? • Register vs. DRAM? • 100x slower • Register vs. disk? • 10,000x slower!!! • These issues matter, timing can be critical in embedded systems.

  14. ATMega328P 8-bit microcontroller Same principles of other systems

  15. Harvard Architecture Flash RAM EEPROM

  16. Three buses EEPROM shares a bus with other I/O devices

  17. Memory Hierarchy 32K Flash 2K SRAM 32 GP Registers (8 bits) 1K EEPROM Memory locations have 8-bit data values Can use higher precision, but over 8-bit and adds are not atomic.

  18. Memory Hierarchy 32K Flash 2K SRAM 32 GP Registers (8 bits) 1K EEPROM Memory locations have 8-bit data values Can use higher precision, but over 8-bit and adds are not atomic. Why is this important to understand?

  19. Memory Hierarchy 32K Flash 2K SRAM 32 GP Registers (8 bits) 1K EEPROM Memory locations have 8-bit data values Can use higher precision, but over 8-bit and adds are not atomic. Why is this important to understand? Interrupts!

  20. Memory Hierarchy 32K Flash 2K SRAM 32 GP Registers (8 bits) 1K EEPROM

  21. Memory Hierarchy 32K Flash 2K SRAM 32 GP Registers (8 bits) 1K EEPROM Why only 32 registers?

  22. Memory Hierarchy 32K Flash 2K SRAM 32 GP Registers (8 bits) 1K EEPROM Why only 32 registers? How many bits do we need to address registers?

  23. Why only 32 registers? • Need 5-bits to address 32 registers • Address lives in an 8-bit instruction • Like to have instructions only take up 8-bits to fetch in one cycle. • 16-bit instructions take two cycles to fetch. • Some instructions are only 8-bits • Five bits will be specifying registers • How many instructions of this sort can we have?

  24. How many 8-bit instructions?

  25. How many 8-bit instructions? • Need on 2-bit pattern to indicate a 16 bit instructions • Only 7 instructions left. • If we had 64 registers, we’d only have 3 fast instructions • Register files are expensive • Not because of the hardware • Due to instruction-space

  26. I/O on Systems • I/O registers • How do you interact with an accelerometer?

  27. I/O on Systems • I/O registers • How do you interact with an accelerometer? • Instruction set doesn’t tell us. Board will. • We can set memory locations from a device on the board. • How do we know when the data is available? • Poll a register • Raise an interrupt

  28. What does C do with a program? • Put static variables in the low addresses • Needs to know about memory! • Dynamic variables in the high addresses (stack).

  29. Understanding the memory architecture char x; x = 0x20; • Where does x live? • What part of memory?

  30. Understanding the memory architecture char x; x = 0x20; • Where does x live? • What part of memory? • If declared outside of a procedure it’s a static variable. • Put it at the lowest address for which there is memory available.

  31. Understanding the memory architecture char x; x = 0x20; • Where does x live? • What part of memory? • If declared inside a procedure?

  32. Understanding the memory architecture char *x; x = 0x20; • Where does x live? • What part of memory? • How much space will it take?

  33. Understanding the memory architecture char *x; x = 0x20; • Where does x live? • What part of memory? • Same as before • How much space will it take? • 2 bytes • 8-bit data, 16-bit addresses

  34. Understanding the memory architecture char *x, y; x = 0x20; y = *x; • What does this program mean?

  35. Understanding the memory architecture char *x, y; x = 0x20; y = *x; • What does this program mean? • y will be whatever is in memory location 0x20 • I/O register • Read the manual to find out what on this hardware y will have.

  36. Understanding the memory architecture char *x, y; x = 0x20; y = *x; • What does this program mean? • y will be whatever is in memory location 0x20 • I/O register • Read the manual to find out what on this hardware y will have. • For ATMega328P • EEPROM Data register

  37. Understanding the memory architecture char *x, y; x = y&; *x = 0x20; • What does this program mean?

  38. Understanding the memory architecture char *x, y; x = y&; *x = 0x20; • What does this program mean? • x will be the address of y • the value of y gets set to 0x20

  39. Understanding the memory architecture char foo() { char *x, y; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean? • Where are x, y, and z in memory?

  40. Understanding the memory architecture char foo() { char *x, y; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean? • Where are x, y, and z in memory? • Static: z • Stack: x, y • How much space do x and y take on the stack?

  41. Understanding the memory architecture char foo() { char *x, y; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean? • Where are x, y, and z in memory? • Static: z • Stack: x, y • How much space do x and y take on the stack? • 2 bytes and 1 byte

  42. Understanding the memory architecture char foo() { char *x, y; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean? • Assigns to y the value of the I/O register (EEPROM Data) 0x20 and returns that value • What does it mean to return a value?

  43. Understanding the memory architecture char foo() { char *x, y; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean? • Assigns to y the value of the I/O register (EEPROM Data) 0x20 and returns that value • What does it mean to return a value? • Return something on the stack… but when it returns stack is invalid memory… • Store it in a register

  44. Understanding the memory architecture char foo() { char y; uint16_t x; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean?

  45. Understanding the memory architecture char foo() { char y; uint16_t x; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean? • uint16_t – unsigned 16bit integer data type

  46. Understanding the memory architecture char foo() { char y; uint16_t x; x = 0x20; y = *x; return y; } char z; int main(void){ z = foo(); … } • What does this program mean? • uint16_t – unsigned 16bit integer data type • x - 2 bytes, y - 1 byte, both stored on the stack. • return whatever is stored at 0x20 again

  47. Memory usage: Understanding the stack.Find the flaw in this program statically allocated: compiler assigns a memory location. int x = 2; int* foo(int y) { int z; z = y * x; return &z; } int main(void) { int* result = foo(10); ... } arguments on the stack automatic variables on the stack program counter and copies of all registers on the stack This program returns a pointer to a variable on the stack. What if another procedure call occurs before the returned pointer is de-referenced?

  48. Memory usage: Understanding the stack.Find the flaw in this program int x = 2; int* foo(int y) { int z; z = y * x; return &z; } int main(void) { int* result = foo(10); ... } • What if the very next instruction reads from the stack? • Will it work?

  49. Memory usage: Understanding the stack.Find the flaw in this program int x = 2; int* foo(int y) { int z; z = y * x; return &z; } int main(void) { int* result = foo(10); ... } • What if the very next instruction reads from the stack? • Will it work? • All the time?

  50. Memory usage: Understanding the stack.Find the flaw in this program int x = 2; int* foo(int y) { int z; z = y * x; return &z; } int main(void) { int* result = foo(10); ... } • What if the very next instruction reads from the stack? • Will it work? • All the time? • What about interrupts?

More Related