Sille Van Landschoot
/
mbed_slave_full
mbed_slave_full
memory.cpp
- Committer:
- sillevl
- Date:
- 2014-10-21
- Revision:
- 6:ec3b01ce9687
- Parent:
- 5:b73ea174e997
File content as of revision 6:ec3b01ce9687:
#include "mbed.h" #include "memory.h" Memory::Memory() { reset(); } /* * Reset all memory locations to 0. */ void Memory::reset() { for (int i = 0; i < Memory::MEMORY_SIZE; i++) { this->memory[i] = 0; } } /* * Store value in memory */ void Memory::set(int address, int value) { if (address < Memory::MEMORY_SIZE) { this->memory[address] = value; } } /* * Retrieve value from memory */ int Memory::get(int address) { if (address < Memory::MEMORY_SIZE) { return this->memory[address]; } else { return 0; } } /* * Print current memory content to console */ void Memory::print() { int i = 0, c = 0; while (i < Memory::MEMORY_SIZE) { c = (c + 1) % 4; printf("\t[%#04x]: %6d", i, this->memory[i]); if (!c) { printf("\r\n"); } i++; } }