/*************************************************************************************|
| 1. YOU ARE NOT ALLOWED TO SHARE/PUBLISH YOUR CODE (e.g., post on piazza or online)|
| OR SHARE YOUR STATE MACHINES |
| 2. Only alter the source code of mipssim.c |
| 3. Do not add any other .c files nor alter mipssim.h, parser.h, definitions.h or |
| memory_hierarchy.c |
| 4. Do not include any other library files |
| —————–DO NOT EDIT THIS FILE!!!!—————————————-|
|*************************************************************************************/
#include “mipssim.h”
void memory_state_init(struct architectural_state* arch_state_ptr) {
arch_state_ptr->memory = (uint32_t *) malloc(sizeof(uint32_t) * MEMORY_WORD_NUM);
memset(arch_state_ptr->memory, 0, sizeof(uint32_t) * MEMORY_WORD_NUM);
memory_stats_init(arch_state_ptr);
}
// returns data on memory[address / 4]
int memory_read(int address){
arch_state.mem_stats.lw_total++;
check_address_is_word_aligned(address);
return (int) arch_state.memory[address / 4];
}
// writes data on memory[address / 4]
void memory_write(int address, int write_data){
arch_state.mem_stats.sw_total++;
check_address_is_word_aligned(address);
arch_state.memory[address / 4] = (uint32_t) write_data;
}