From 2ff465ec880107691e3aa288574a3049f5276af2 Mon Sep 17 00:00:00 2001
From: Ben Bridle <bridle.benjamin@gmail.com>
Date: Tue, 9 Jan 2024 11:42:44 +1300
Subject: Report program size as a percentage

The assembler previously reported only the length of the generated
bytecode in bytes. It now also reports the program size as a percentage
of the maximum program size of 64KB, to give the user an idea of how
close they are to hitting the program size limit.
---
 src/main.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/main.rs b/src/main.rs
index d9683a3..11ce42b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,7 +26,9 @@ fn main() {
         eprintln!();
     }
 
-    eprintln!("Assembled program in {} bytes.", bytecode.len());
+    let byte_count = bytecode.len();
+    let byte_percentage = (byte_count as f32 / 65536.0 * 100.0).round() as u16;
+    eprintln!("Assembled program in {byte_count} bytes ({byte_percentage}% of maximum).");
 
     if is_error {
         std::process::exit(1)
-- 
cgit v1.2.3-70-g09d2