jump indirect seems to be working as well
This commit is contained in:
@@ -18,7 +18,7 @@ jump_instruction = {"JMP"}
|
||||
arg_instruction = {"LDA" | "ADD" | "SUB"}
|
||||
no_arg_instruction = { "NOP" }
|
||||
|
||||
jump_argument = { jump_location | label }
|
||||
jump_argument = { jump_location | label | memory_location }
|
||||
argument = { memory_location | digit_literal }
|
||||
memory_location = { "(" ~ ASCII_HEX_DIGIT ~")" }
|
||||
digit_literal = {"#" ~ ASCII_HEX_DIGIT}
|
||||
|
||||
@@ -14,6 +14,7 @@ pub struct Label<'a> {
|
||||
pub enum JumpArgument<'a> {
|
||||
Location(u8),
|
||||
Label(&'a str),
|
||||
MemoryLocation(u8),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -68,6 +68,12 @@ pub fn generate_binary(instructions: Vec<Instruction>) -> Program {
|
||||
} else {
|
||||
panic!("Tried to JMP to label: {}, which does not exist", arg);
|
||||
}
|
||||
},
|
||||
JumpArgument::MemoryLocation(address) => {
|
||||
BinaryInstruction {
|
||||
opcode: 12,
|
||||
argument: *address
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -169,6 +169,11 @@ fn parse_jump_argument<'a>(arg: Pair<'a, Rule>) -> JumpArgument<'a> {
|
||||
Rule::label => JumpArgument::Label(arg.as_str()),
|
||||
Rule::jump_location => {
|
||||
JumpArgument::Location(u8::from_str_radix(arg.as_str(), 16).unwrap())
|
||||
},
|
||||
Rule::memory_location => {
|
||||
let arg_string = arg.as_str();
|
||||
let arg_value = u8::from_str_radix(&arg_string[1..arg_string.len() - 1], 16).unwrap();
|
||||
JumpArgument::MemoryLocation(arg_value)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
@@ -138,6 +138,12 @@ pub fn simulate<'a>(instructions: Vec<Instruction<'a>>, max_steps: usize) -> Vec
|
||||
} else {
|
||||
panic!("Tried to JMP to label: {}, which does not exist", arg);
|
||||
}
|
||||
},
|
||||
JumpArgument::MemoryLocation(address) => {
|
||||
BinaryInstruction {
|
||||
opcode: 12,
|
||||
argument: address
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -205,6 +211,10 @@ pub fn simulate<'a>(instructions: Vec<Instruction<'a>>, max_steps: usize) -> Vec
|
||||
next_pc = Some(location);
|
||||
addr_bus = location;
|
||||
},
|
||||
JumpArgument::MemoryLocation(location) => {
|
||||
next_pc = Some(data_memory[location as usize]);
|
||||
addr_bus = data_memory[location as usize];
|
||||
}
|
||||
},
|
||||
Instruction::MemoryLocationInstruction(arg, _) => match arg {
|
||||
MemoryLocationInstruction::STA(arg) => {
|
||||
|
||||
Reference in New Issue
Block a user