From ea904bfb7d0c4a103d88b0890f48aec302136f05 Mon Sep 17 00:00:00 2001 From: thealmarty <“thealmartyblog@gmail.com”> Date: Thu, 18 Apr 2024 11:31:39 -0700 Subject: [PATCH] Add to assembler/REPL. --- assembler/grammar/assembly.pest | 2 +- assembler/src/lib.rs | 4 ++-- machine/src/program.rs | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/assembler/grammar/assembly.pest b/assembler/grammar/assembly.pest index 530aa40..82cea9e 100644 --- a/assembler/grammar/assembly.pest +++ b/assembler/grammar/assembly.pest @@ -3,7 +3,7 @@ comment = { ";" ~ (!"\n" ~ ANY)* ~ "\n" } label = { (!":" ~ !"\n" ~ ANY)+ ~ ":" ~ "\n" } instruction = { mnemonic ~ (operand ~ ", "?)+? ~ "\n"? } mnemonic = { - "lw" | "sw" | "jalv" | "jal" | "beqi" | "beq" | "bnei" | "bne" | "imm32" | "stop" | + "lw" | "sw" | "loadu8" | "loads8" | "storeu8" | "jalv" | "jal" | "beqi" | "beq" | "bnei" | "bne" | "imm32" | "stop" | "advread" | "advwrite" | "addi" | "add" | "subi" | "sub" | "muli" | "mul" | "mulhsi"| "mulhui"| "mulhs"| "mulhu" | "divi" | "div" | "sdiv" | "sdivi" | "ilte" | "ltei" | "lte" | "ilt" | "lti" | "lt" | "shli" | "shl" | "shri" | "shr" | "srai" | "sra" | diff --git a/assembler/src/lib.rs b/assembler/src/lib.rs index 5d0c1e9..b3ed64b 100644 --- a/assembler/src/lib.rs +++ b/assembler/src/lib.rs @@ -104,12 +104,12 @@ pub fn assemble(input: &str) -> Result, String> { // Insert zero operands if necessary match mnemonic { - "lw" => { + "lw" | "loadu8" | "loads8" => { // (a, 0, c, 0, 0) operands.insert(1, 0); operands.extend(vec![0; 2]); } - "sw" => { + "sw" | "storeu8" => { // (0, b, c, 0, 0) operands.insert(0, 0); operands.extend(vec![0; 2]); diff --git a/machine/src/program.rs b/machine/src/program.rs index f61bcba..3032f8c 100644 --- a/machine/src/program.rs +++ b/machine/src/program.rs @@ -102,9 +102,18 @@ impl InstructionWord { valida_opcodes::LOAD32 => { format!("{}(fp), {}(fp)", self.operands.0[0], self.operands.0[2]) } + valida_opcodes::LOADU8 => { + format!("{}(fp), {}(fp)", self.operands.0[0], self.operands.0[2]) + } + valida_opcodes::LOADS8 => { + format!("{}(fp), {}(fp)", self.operands.0[0], self.operands.0[2]) + } valida_opcodes::STORE32 => { format!("{}(fp), {}(fp)", self.operands.0[1], self.operands.0[2]) } + valida_opcodes::STOREU8 => { + format!("{}(fp), {}(fp)", self.operands.0[1], self.operands.0[2]) + } _ => { format!( "{}(fp), {}, {}",