summaryrefslogtreecommitdiff
path: root/src/formats/raw.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/formats/raw.rs')
-rw-r--r--src/formats/raw.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/formats/raw.rs b/src/formats/raw.rs
index ecc6473..4cd0338 100644
--- a/src/formats/raw.rs
+++ b/src/formats/raw.rs
@@ -1,7 +1,11 @@
use crate::*;
+pub enum Endian {
+ Big,
+ Little,
+}
-pub fn format_raw(segments: &[Segment], width: Option<u32>) -> Result<Vec<u8>, FormatError> {
+pub fn format_raw(segments: &[Segment], width: Option<u32>, endian: Endian) -> Result<Vec<u8>, FormatError> {
let Some(width) = width.or_else(|| calculate_fixed_width(&segments)) else {
return Err(FormatError::ExpectedFixedWidth);
};
@@ -17,10 +21,18 @@ pub fn format_raw(segments: &[Segment], width: Option<u32>) -> Result<Vec<u8>, F
for word in &segment.words {
// Decompose word value into bytes.
let value = word.value.value;
- for i in (0..bytes_per_word).rev() {
- let byte = (value >> (i*8) & 0xff) as u8;
- bytes.push(byte);
- }
+ match endian {
+ Endian::Big =>
+ for i in (0..bytes_per_word).rev() {
+ let byte = (value >> (i*8) & 0xff) as u8;
+ bytes.push(byte);
+ }
+ Endian::Little =>
+ for i in 0..bytes_per_word {
+ let byte = (value >> (i*8) & 0xff) as u8;
+ bytes.push(byte);
+ }
+ };
address += 1;
}
}