Skip to content

Commit 526cf13

Browse files
committed
feat(memory) Implemented memory instruction format.
1 parent 979bc77 commit 526cf13

File tree

7 files changed

+81
-31
lines changed

7 files changed

+81
-31
lines changed

src/instruction.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
pub mod branch;
2+
pub mod memory;
3+
pub mod register;
4+
pub mod flag;
5+
16
use crate::num;
2-
use crate::operation::branch;
3-
use crate::state::flag::Flag;
4-
use crate::state::register::Register;
7+
use flag::Flag;
8+
use register::Register;
59

610
#[derive(Debug, Clone, Copy, PartialEq)]
711
pub enum RegisterOperation {
@@ -10,16 +14,11 @@ pub enum RegisterOperation {
1014

1115
#[derive(Debug, Clone, Copy, PartialEq)]
1216
pub enum SizedRegisterOperation {
13-
14-
}
1517

16-
#[derive(Debug, Clone, Copy, PartialEq)]
17-
pub enum DualSizedRegisterOperation {
18-
1918
}
2019

2120
#[derive(Debug, Clone, Copy, PartialEq)]
22-
pub enum ConditionalBranchOperation {
21+
pub enum DualSizedRegisterOperation {
2322

2423
}
2524

@@ -28,14 +27,18 @@ pub enum Instruction {
2827
Nothing,
2928
WaitForInterrupt,
3029
Register { operation: RegisterOperation, register: Register },
31-
SizedRegister {
32-
operation: SizedRegisterOperation,
30+
SizedRegister {
31+
operation: SizedRegisterOperation,
3332
size: num::Size, register: Register },
3433
DualSizedRegister {
3534
operation: DualSizedRegisterOperation,
3635
size: num::Size, registers: [Register; 2] },
37-
ConditionalBranch {
38-
operation: ConditionalBranchOperation,
36+
Branch {
37+
operation: branch::Operation,
3938
condition: Option<Flag>, hint: branch::Hint,
40-
address: branch::Address }
41-
}
39+
address: branch::Address },
40+
Memory {
41+
operation: memory::Operation,
42+
size: num::Size, register: Register,
43+
address: memory::Address }
44+
}

src/operation/branch.rs src/instruction/branch.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use crate::num;
2-
use crate::state::flag::Flag;
3-
use crate::state::register::Register;
2+
use crate::instruction::flag::Flag;
3+
use crate::instruction::register::Register;
4+
5+
#[derive(Debug, Clone, Copy, PartialEq)]
6+
pub enum Operation {
7+
8+
}
49

510
/// Hint to suggest whether the branch might be taken.
611
pub type Hint = Option<bool>;
@@ -33,7 +38,7 @@ pub type ConditionCode = num::MaskedU8<CONDITION_MASK>;
3338
#[derive(Debug, Clone, Copy, PartialEq)]
3439
pub struct ConditionMapping {
3540
pub code: ConditionCode,
36-
pub variant: Condition
41+
pub variant: Condition
3742
}
3843

3944
impl Condition {
@@ -46,17 +51,17 @@ impl Condition {
4651
Condition(Some(Flag::Parity )),
4752
Condition(Some(Flag::Auxiliary ))
4853
];
49-
50-
pub fn from_code(code: ConditionCode) -> Option<Self> {
51-
Self::MAPPINGS.get(code.get() as usize).copied()
54+
55+
pub fn from_code(code: ConditionCode) -> Self {
56+
*Self::MAPPINGS
57+
.get(code.get() as usize)
58+
.unwrap_or(&Self::MAPPINGS[0])
5259
}
53-
60+
5461
pub fn to_code(self) -> ConditionCode {
55-
ConditionCode::new(
56-
Self::MAPPINGS
57-
.iter()
58-
.position(|&mapping| mapping == self)
59-
.unwrap() as u8,
60-
)
62+
ConditionCode::new(Self::MAPPINGS
63+
.iter()
64+
.position(|&mapping| mapping == self)
65+
.unwrap() as u8)
6166
}
6267
}
File renamed without changes.

src/instruction/memory.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::instruction::register::Register;
2+
use crate::num;
3+
4+
#[derive(Debug, Clone, Copy, PartialEq)]
5+
pub enum Operation {
6+
7+
}
8+
9+
#[derive(Debug, Clone, Copy, PartialEq)]
10+
pub enum Mode {
11+
Absolute,
12+
Relative
13+
}
14+
15+
pub const BASE_IMMEDIATE_OFFSET_MASK: u16 = 0x0C;
16+
pub type BaseImmediateOffset = num::MaskedU16<BASE_IMMEDIATE_OFFSET_MASK>;
17+
pub type BaseIndexImmediateOffset = u8;
18+
19+
#[derive(Debug, Clone, Copy, PartialEq)]
20+
pub enum IndexMode {
21+
Offset(BaseIndexImmediateOffset),
22+
RegisterOffset(Register)
23+
}
24+
25+
#[derive(Debug, Clone, Copy, PartialEq)]
26+
pub enum BaseMode {
27+
Offset(BaseImmediateOffset),
28+
RegisterOffset(Register),
29+
Index {
30+
mode: IndexMode,
31+
index: Register }
32+
}
33+
34+
#[derive(Debug, Clone, Copy, PartialEq)]
35+
pub enum Address {
36+
Immediate {
37+
mode: Mode,
38+
immediate: u16 },
39+
Register {
40+
mode: Mode,
41+
register: Register },
42+
Base {
43+
mode: BaseMode,
44+
base: Register }
45+
}
File renamed without changes.

src/operation.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
pub mod branch;

src/state.rs

-2
This file was deleted.

0 commit comments

Comments
 (0)