Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
memory.cpp
00001 #include "mbed.h" 00002 #include "memory.h" 00003 00004 Memory::Memory() 00005 { 00006 reset(); 00007 } 00008 00009 /* 00010 * Reset all memory locations to 0. 00011 */ 00012 void Memory::reset() 00013 { 00014 for (int i = 0; i < Memory::MEMORY_SIZE; i++) { 00015 this->memory[i] = 0; 00016 } 00017 } 00018 00019 /* 00020 * Store value in memory 00021 */ 00022 void Memory::set(int address, int value) 00023 { 00024 if (address < Memory::MEMORY_SIZE) { 00025 this->memory[address] = value; 00026 } 00027 } 00028 00029 /* 00030 * Retrieve value from memory 00031 */ 00032 int Memory::get(int address) 00033 { 00034 if (address < Memory::MEMORY_SIZE) { 00035 return this->memory[address]; 00036 } else { 00037 return 0; 00038 } 00039 } 00040 00041 /* 00042 * Print current memory content to console 00043 */ 00044 void Memory::print() 00045 { 00046 int i = 0, c = 0; 00047 while (i < Memory::MEMORY_SIZE) { 00048 c = (c + 1) % 4; 00049 printf("\t[%#04x]: %6d", i, this->memory[i]); 00050 if (!c) { 00051 printf("\r\n"); 00052 } 00053 i++; 00054 } 00055 }
Generated on Sat Aug 6 2022 19:26:06 by
1.7.2