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 0436bff commit 9be668c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 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
6 changes: 3 additions & 3 deletions cpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::marker::Sync;
use core::mem::transmute;
use valida_bus::{MachineWithGeneralBus, MachineWithMemBus, MachineWithProgramBus};
use valida_machine::{
index_of_byte, addr_of_word, instructions, AdviceProvider, Chip, Instruction, InstructionWord,
addr_of_word, index_of_byte, instructions, AdviceProvider, Chip, Instruction, InstructionWord,
Interaction, Operands, Word,
};
use valida_memory::{MachineWithMemoryChip, Operation as MemoryOperation};
Expand Down Expand Up @@ -532,9 +532,9 @@ where
let read_addr = state
.mem_mut()
.read(clk, read_addr_loc, true, pc, opcode, 0, "");

let read_addr_index = addr_of_word(read_addr.into());

// The word from the read address.
let cell = state.mem_mut().read(
clk,
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 9be668c

Please sign in to comment.