diff options
author | David Li <li.davidm96@gmail.com> | 2015-12-18 21:20:36 -0500 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2015-12-18 21:20:36 -0500 |
commit | fd582a1cbd091576701d12e886d9ad91527320f9 (patch) | |
tree | 1b1a2d1cb32cbdb51765939f3a41790e05cc5d8f /src/memory.rs | |
parent | eaf81f3ea63098a908476d05886c8f00ac7e9389 (diff) |
Implement RV32I integer-register instructions
Diffstat (limited to 'src/memory.rs')
-rw-r--r-- | src/memory.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/memory.rs b/src/memory.rs index 3409ed4..b7e3721 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -22,6 +22,17 @@ impl Memory { self.memory.get(address / 4).map(Clone::clone) } + pub fn write_word(&mut self, address: usize, value: u32) -> Option<()> { + let address = address / 4; + if address >= self.memory.len() { + None + } + else { + self.memory[address] = value; + Some(()) + } + } + pub fn read_instruction(&self, pc: usize) -> Option<Instruction> { self.memory.get(pc / 4).map(Clone::clone).map(Instruction::new) } |