Skip to content

Commit

Permalink
Add to assembler/REPL.
Browse files Browse the repository at this point in the history
  • Loading branch information
thealmarty committed Apr 18, 2024
1 parent baa3d4d commit ea904bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assembler/grammar/assembly.pest
Original file line number Diff line number Diff line change
Expand Up @@ -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" |
Expand Down
4 changes: 2 additions & 2 deletions assembler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ pub fn assemble(input: &str) -> Result<Vec<u8>, 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]);
Expand Down
9 changes: 9 additions & 0 deletions machine/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,18 @@ impl InstructionWord<i32> {
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), {}, {}",
Expand Down

0 comments on commit ea904bf

Please sign in to comment.