Skip to main content

hello_world/
hello_world.rs

1// Example: Simple "Hello World" TAL program assembly
2
3use uxn_tal::{Assembler, AssemblerError};
4
5fn main() -> Result<(), AssemblerError> {
6    let tal_source = r#"
7        ( Simple Hello World Program )
8        
9        |0100 @reset
10            #48 #65 #6c #6c #6f #20 #57 #6f #72 #6c #64 #21 #0a
11            #18 DEO
12        BRK
13    "#;
14
15    let mut assembler = Assembler::new();
16    match assembler.assemble(tal_source, Some("hello_world.rs".to_owned())) {
17        Ok(rom) => {
18            println!("Successfully assembled {} bytes", rom.len());
19
20            // Save to file
21            std::fs::write("hello.rom", &rom)?;
22            println!("ROM saved to hello.rom");
23
24            // Print first few bytes for verification
25            println!("First 16 bytes:");
26            for (i, byte) in rom.iter().take(16).enumerate() {
27                if i % 8 == 0 {
28                    print!("\n{:04x}: ", i);
29                }
30                print!("{:02x} ", byte);
31            }
32            println!();
33
34            Ok(())
35        }
36        Err(e) => {
37            eprintln!("Assembly failed: {}", e);
38            Err(e)
39        }
40    }
41}