diff options
| Commit | 13bc44e09c4e0cb2f4e9f90843716624e4c1cde1 (patch) | |
|---|---|---|
| Author | 2025-02-14 00:45:40 +0200 | |
| Committer | 2025-02-14 00:45:40 +0200 | |
| Files | dceff1a98062d9887b30d8586a1d6466faa6ef01 /assembler/src/parser | |
| tonkobali-13bc44e09c4e0cb2f4e9f90843716624e4c1cde1.tar tonkobali-13bc44e09c4e0cb2f4e9f90843716624e4c1cde1.tar.gz tonkobali-13bc44e09c4e0cb2f4e9f90843716624e4c1cde1.zip | ||
| Parent | cf56360e18a05da6c55148b2011fd22f8224bfef (diff) | |
fix(assembler): Fix addressing
2 files changed, 10 insertions, 3 deletions
| -rw-r--r-- | assembler/src/parser/code_gen.rs | 4 | ||||
| -rw-r--r-- | assembler/src/parser/instruction.rs | 9 |
diff --git a/assembler/src/parser/code_gen.rs b/assembler/src/parser/code_gen.rs index 92bf1d1..7d6fc45 100644 --- a/assembler/src/parser/code_gen.rs +++ b/assembler/src/parser/code_gen.rs @@ -27,8 +27,10 @@ impl Program { /* Machine code generation */ - pub(crate) fn instructions_to_constants(&mut self, absolute_start: usize) { + pub(crate) fn instructions_to_constants(&mut self, mut absolute_start: usize) { + absolute_start += 1; let constlen = self.constants.len(); + self.constants.insert(0, (absolute_start + constlen) as Word); for instr in &mut self.instructions { for arg in &mut instr.args { diff --git a/assembler/src/parser/instruction.rs b/assembler/src/parser/instruction.rs index 8c8e8aa..f78c9a6 100644 --- a/assembler/src/parser/instruction.rs +++ b/assembler/src/parser/instruction.rs @@ -8,15 +8,20 @@ impl Instruction { } } - pub(crate) fn collapse(&mut self) -> Vec<Instruction> { + pub(crate) fn collapse(&mut self, next: usize) -> Vec<Instruction> { self.name = self.name.to_lowercase(); static Z: Address = Address::Memory(0); match &*self.name { - "subleq" | "add" | "mult" => vec![self.clone()], + "subleq" => vec![self.clone()], "jmp" => vec![ Instruction::new_subleq(&Z, &Z, &self.args[0]), ], + "add" => vec![ + Instruction::new_subleq(&self.args[0], &Z, &Address::Instruction(next + 1)), + Instruction::new_subleq(&Z, &self.args[1], &Address::Instruction(next + 2)), + Instruction::new_subleq(&Z, &Z, &Address::Instruction(next + 3)), + ], _ => panic!("Unknown instruction {}!", self.name), } } |
