Struct lc3_ensemble::sim::mem::Word
source · pub struct Word { /* private fields */ }Expand description
A memory location that can be read and written to.
§Reading
A word’s value can be read with Word::get
to return its representation as an unsigned integer.
This can be converted to a signed integer with typical as casting (data as i16).
§Writing
A word can be written into with a value or with another word.
Word::setto read a value into this wordWord::copy_wordto read a word into this word
Word::copy_word may be more useful in situations where initialization state may want to be preserved.
See the respective functions for more details.
Words can also be written to by applying assign operations (e.g., add, sub, and, etc.). All arithmetic operations that can be applied to words are assumed to be wrapping. See those implementations for more details.
§Initialization
Internally, each memory location keeps track of two fields:
- its data (i.e., the value stored at this location)
- which bits of its data are truly “initialized” (as in the program knows what values are present there)
This second field is not used except for when the simulator is set to strict mode. Then, this second field is leveraged to detect if uninitialized memory is being written to places it shouldn’t be (e.g., PC, addresses, registers and memory).
When a Word is created for memory/register files (i.e., via Word::new_uninit),
it is created with the initialization bits set to fully uninitialized.
The data associated with this Word is decided by the creation strategy
(see WordCreateStrategy for details).
Implementations§
source§impl Word
impl Word
sourcepub fn new_uninit(strat: &mut WordCreateStrategy) -> Self
pub fn new_uninit(strat: &mut WordCreateStrategy) -> Self
Creates a new word that is considered uninitialized.
sourcepub fn new_init(data: u16) -> Self
pub fn new_init(data: u16) -> Self
Creates a new word that is initialized with a given data value.
sourcepub fn clear_init(&mut self)
pub fn clear_init(&mut self)
Clears initialization of this word.
sourcepub fn set(&mut self, data: u16)
pub fn set(&mut self, data: u16)
Writes to the word.
The data provided is assumed to be FULLY initialized, and will set the initialization state of this word to be fully initialized.
If the data is not fully initialized (e.g., if it is a partially initialized word),
Word::copy_word can be used instead.
sourcepub fn copy_word(
&mut self,
word: Word,
strict: bool,
err: SimErr
) -> Result<(), SimErr>
pub fn copy_word( &mut self, word: Word, strict: bool, err: SimErr ) -> Result<(), SimErr>
Copies the data from one word into another.
This function is more cognizant of word initialization than Word::set.
- In non-strict mode, this function preserves the initialization data of the given word.
- In strict mode, this function verifies the word copied is fully initialized, raising the provided error if not.
Trait Implementations§
source§impl Add for Word
impl Add for Word
source§impl AddAssign<i16> for Word
impl AddAssign<i16> for Word
source§fn add_assign(&mut self, rhs: i16)
fn add_assign(&mut self, rhs: i16)
Increments the word by the provided value.
If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.
source§impl AddAssign<u16> for Word
impl AddAssign<u16> for Word
source§fn add_assign(&mut self, rhs: u16)
fn add_assign(&mut self, rhs: u16)
Increments the word by the provided value.
If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.
source§impl AddAssign for Word
impl AddAssign for Word
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl BitAndAssign for Word
impl BitAndAssign for Word
source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moresource§impl Sub for Word
impl Sub for Word
source§impl SubAssign<i16> for Word
impl SubAssign<i16> for Word
source§fn sub_assign(&mut self, rhs: i16)
fn sub_assign(&mut self, rhs: i16)
Decrements the word by the provided value.
If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.
source§impl SubAssign<u16> for Word
impl SubAssign<u16> for Word
source§fn sub_assign(&mut self, rhs: u16)
fn sub_assign(&mut self, rhs: u16)
Decrements the word by the provided value.
If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.
source§impl SubAssign for Word
impl SubAssign for Word
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more