~jpl8/lorthc3

855334239a6a25ea726d0bcf41bb93c08cb26579 — jpl 1 year, 27 days ago afdf69f
Add working word lookup
2 files changed, 9 insertions(+), 1 deletions(-)

M src/assembler.rs
M src/compiler.rs
M src/assembler.rs => src/assembler.rs +8 -1
@@ 143,7 143,7 @@ impl LC3Assembler {
                    self.asm_addr_to_offset(addr)? as Word,
                )),
                TRAP(trap) => PseudoInstruction::LC3(Instruction::TRAP(trap)),
                FILL(addr) => PseudoInstruction::FILL(self.asm_addr_to_offset(addr)? as Word),
                FILL(addr) => PseudoInstruction::FILL(self.asm_addr_abs(addr)? as Word),
            };

            assembled_instructions.push(assembled);


@@ 161,6 161,13 @@ impl LC3Assembler {
        }
    }

    fn asm_addr_abs(&self, addr: AsmAddr) -> Result<SignedWord> {
        match addr {
            AsmAddr::Word(w) => Ok(w as SignedWord),
            AsmAddr::Label(label, _) => Ok(self.get_label_addr(label)? as SignedWord),
        }
    }

    pub fn get_label_addr(&self, label: String) -> Result<Word> {
        if let Some(addr) = self.labels.get(&label) {
            Ok(*addr)

M src/compiler.rs => src/compiler.rs +1 -0
@@ 256,6 256,7 @@ impl ForthCompiler {
        let next = self.asm.reference_label("next");
        self.asm.branch_unconditionally(next);

        // halt
        self.word(String::from("bye"), 0).asm.halt();
        let next = self.asm.reference_label("next");
        self.asm.branch_unconditionally(next);