diff --git a/src/emulator/instructions/mod.rs b/src/emulator/instructions/mod.rs index 965db62..5a67dae 100644 --- a/src/emulator/instructions/mod.rs +++ b/src/emulator/instructions/mod.rs @@ -1 +1,2 @@ pub mod arithmetic; +pub mod transfer; diff --git a/src/emulator/instructions/transfer.rs b/src/emulator/instructions/transfer.rs new file mode 100644 index 0000000..e39251c --- /dev/null +++ b/src/emulator/instructions/transfer.rs @@ -0,0 +1,10 @@ +use crate::{get_register, set_register, EmulatorState, Register}; + +pub fn mov(src: Register, dest: Register, state: &mut EmulatorState) { + let data = get_register(src, state); + set_register(dest, data, state); +} + +pub fn mvi(byte: u8, dest: Register, state: &mut EmulatorState) { + set_register(dest, byte, state); +} diff --git a/src/emulator/main.rs b/src/emulator/main.rs index 0569b02..6f6bf3c 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -1,4 +1,4 @@ -use instructions::arithmetic; +use instructions::{arithmetic, transfer}; use std::{env, fs}; use crate::structs::*; @@ -72,6 +72,21 @@ fn tick(state: &mut EmulatorState) { } } + /* Data Transfer */ + // MVI + 0x06 | 0x0e | 0x16 | 0x1e | 0x26 | 0x2e | 0x36 | 0x3e => transfer::mvi( + next_byte(), + register_from_num((instruction & 0x38) >> 3), + state, + ), + + // MOV + 0x40..=0x7f => transfer::mov( + register_from_num(instruction & 0x7), + register_from_num((instruction & 0x38) >> 3), + state, + ), + /* Maths */ // INR 0x04 => arithmetic::inr(Register::B, state),