From 1ecee352f5844b0809d7ae66df52e34f42b44c8e Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 6 Mar 2025 20:33:27 +1300 Subject: Rewrite entire assembler The language is now more general, the code is better structured, error reporting is more detailed, and many new language features have been implemented: - conditional blocks - first-class strings - more expression operators - binary literals - negative values - invocations in constant expressions --- src/formats/debug.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/formats/debug.rs (limited to 'src/formats/debug.rs') diff --git a/src/formats/debug.rs b/src/formats/debug.rs new file mode 100644 index 0000000..23fd34f --- /dev/null +++ b/src/formats/debug.rs @@ -0,0 +1,18 @@ +use crate::*; + + +pub fn format_debug(segments: &[Segment]) -> Result, FormatError> { + let mut output = String::new(); + for segment in segments { + // Find maximum width of all words in the segment. + let width = segment.words.iter().map(|w| w.to_string().chars().count()).max().unwrap_or(0); + let address = &segment.address; + output.push_str(&format!("SEGMENT: 0x{address:>04x}\n")); + for word in &segment.words { + let string = word.to_string(); + let w = width as usize; + output.push_str(&format!(" {string:>w$}\n")); + } + } + return Ok(output.as_bytes().to_vec()); +} -- cgit v1.2.3-70-g09d2