Skip to content

Commit

Permalink
Add OPs table
Browse files Browse the repository at this point in the history
  • Loading branch information
rozukke committed May 10, 2024
1 parent 8094b29 commit 914a3f3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
69 changes: 69 additions & 0 deletions src/ops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use crate::state::Flag;
use crate::symbol::Register;

enum Opcodes {
// Add SR1 (source register 1) with SR2 and store in DR (destination register)
ADD {
dest_r: Register,
src_r_1: Register,
src_r_2: Choice,
},
// Bitwise AND SR1 with SR2 and store in DR
AND {
dest_r: Register,
src_r_1: Register,
src_r_2: Choice,
},
// Branch based on flag by adding offset to PC
BR {
cc: Flag,
pc_offset9: u16,
},
// Set PC to BaseR
JMP {
base_r: Register,
},
JSR {
pc_offset11: u16,
},
JSRR {
base_r: Register,
},
LD {
dest_r: Register,
pc_offset9: u16,
},
LDI {
dest_r: Register,
pc_offset9: u16,
},
LDR {
dest_r: Register,
base_r: Register,
pc_offset6: u16,
},
LEA {
dest_r: Register,
pc_offset9: u16,
},
NOT {
dest_r: Register,
src_r: Register,
},
RET,
RTI,
ST {
src_r: Register,
pc_offset9: u16,
},
STI {
src_r: Register,
pc_offset9: u16,
},
}

// ADD and AND commands support immediate value
enum Choice {
Reg(Register),
Imm5(u8),
}
2 changes: 1 addition & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct State {
}

// Set using result from previous instruction
enum Flag {
pub enum Flag {
// Negative
N,
// Zero
Expand Down
10 changes: 10 additions & 0 deletions src/symbol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub enum Register {
R0 = 0,
R1,
R2,
R3,
R4,
R5,
R6,
R7,
}

0 comments on commit 914a3f3

Please sign in to comment.