diff options
| author | Ben Bridle <ben@derelict.engineering> | 2026-11-09 18:03:35 +1300 |
|---|---|---|
| committer | Ben Bridle <ben@derelict.engineering> | 2026-11-09 18:04:39 +1300 |
| commit | 5d32e6a3936af7594ab046c66a5240b350a2bea7 (patch) | |
| tree | 7cd391bbd9cdb2869db7bdda2307251d27d9c7d5 /src/formats/raw.rs | |
| parent | 255fd76c527026387b0f074d5a3f9808037ca449 (diff) | |
| download | torque-asm-5d32e6a3936af7594ab046c66a5240b350a2bea7.zip | |
This is the same as 'raw', but produces bytes in little-endian order.
Diffstat (limited to 'src/formats/raw.rs')
| -rw-r--r-- | src/formats/raw.rs | 22 |
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; } } |
