diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-06 22:36:34 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-06 22:36:34 +1000 |
| commit | 7a8d2bcd75d88a5429937bf551878c55e1dcf0fd (patch) | |
| tree | 81bc1f259fb8678513aa8b214df4ef72720bb585 /Assembler/Program.cs | |
| parent | 16f3cb74564cf7c19da6e13666c98aca36094716 (diff) | |
moved everything to seperate projects, and started compiler work + push and pop instructions added
Diffstat (limited to 'Assembler/Program.cs')
| -rw-r--r-- | Assembler/Program.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Assembler/Program.cs b/Assembler/Program.cs new file mode 100644 index 0000000..b30df1e --- /dev/null +++ b/Assembler/Program.cs @@ -0,0 +1,38 @@ +namespace Q1.Assembler; + +using CommandLine; + +public class Program +{ + static void Main(string[] args) + { + Parser.Default.ParseArguments<Options>(args).WithParsed(Program.Main); + } + + static void Main(Options options) + { + Environment.CurrentDirectory = Path.GetDirectoryName(options.InputFile) ?? Environment.CurrentDirectory; + options.InputFile = Path.GetFileName(options.InputFile); + + string[] input = File.ReadAllLines(options.InputFile); + + try + { + Assembler assembler = new(input); + byte[] bin = assembler.Assemble().ToArray(); + if (bin.Length > 8 * 1024) + throw new AssemblerException("Assembled binary exceeds maximum size of 8KB."); + + File.WriteAllBytes(options.OutputFile, bin); + + Console.WriteLine($"Assembled {options.InputFile} to {options.OutputFile} ({bin.Length} bytes)"); + } + catch (AssemblerException ex) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Error: {ex.Message}"); + Console.ResetColor(); + Environment.Exit(1); + } + } +}
\ No newline at end of file |
