move instructions

This commit is contained in:
Martin Löffler 2023-01-26 05:30:14 +01:00
parent ed05dd5d30
commit 6abdd5dff3
Signed by: FatalErrorCoded
GPG key ID: FFEF368AC076566A
3 changed files with 27 additions and 1 deletions

View file

@ -1 +1,2 @@
pub mod arithmetic; pub mod arithmetic;
pub mod transfer;

View file

@ -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);
}

View file

@ -1,4 +1,4 @@
use instructions::arithmetic; use instructions::{arithmetic, transfer};
use std::{env, fs}; use std::{env, fs};
use crate::structs::*; 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 */ /* Maths */
// INR // INR
0x04 => arithmetic::inr(Register::B, state), 0x04 => arithmetic::inr(Register::B, state),