From 6abdd5dff31a4835ebff02a46c4c0baeec8a5957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6ffler?= Date: Thu, 26 Jan 2023 05:30:14 +0100 Subject: [PATCH] move instructions --- src/emulator/instructions/mod.rs | 1 + src/emulator/instructions/transfer.rs | 10 ++++++++++ src/emulator/main.rs | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/emulator/instructions/transfer.rs 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),