ft(interpreter): impl basic call
This commit is contained in:
@@ -202,14 +202,14 @@ pub enum Mnemonic {
|
|||||||
CBW,
|
CBW,
|
||||||
CWD,
|
CWD,
|
||||||
// CALL
|
// CALL
|
||||||
CALL_p(Pointer32),
|
CALL_p(Pointer32), // 0x9A
|
||||||
CALL_v(usize),
|
CALL_v(usize), // 0xE8
|
||||||
CALL_Mod(ModRmTarget),
|
CALL_Mod(ModRmTarget), // 0xFF 2
|
||||||
CALL_Mp(Pointer16),
|
CALL_Mp(Pointer16), // 0xFF 3
|
||||||
// JUMP
|
// JUMP
|
||||||
JMP_p(Pointer32),
|
JMP_p(Pointer32),
|
||||||
JMP_b(usize), // parses IByte, but stores as isize
|
JMP_b(usize),
|
||||||
JMP_v(usize), // parwses IWord, but stores as isize
|
JMP_v(usize),
|
||||||
JMP_Mod(ModRmTarget),
|
JMP_Mod(ModRmTarget),
|
||||||
JMP_Mp(Pointer16),
|
JMP_Mp(Pointer16),
|
||||||
// WAIT
|
// WAIT
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::{fmt::Debug, process::exit};
|
use std::{env::current_dir, fmt::Debug, process::exit};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
instructions::{Instruction, Mnemonic},
|
instructions::{Instruction, Mnemonic},
|
||||||
@@ -413,6 +413,17 @@ impl Interpreter {
|
|||||||
self.computer.regs.read(register).into(),
|
self.computer.regs.read(register).into(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
Mnemonic::CALL_p(_) => todo!(),
|
||||||
|
Mnemonic::CALL_v(offset) => {
|
||||||
|
// save next instruction onto stack for later RET
|
||||||
|
if let Some(next_instr) = ip.next() {
|
||||||
|
self.computer.push_stack(next_instr.start.into())?;
|
||||||
|
}
|
||||||
|
// jump to target
|
||||||
|
Self::ip_jump(&self.instructions, &mut ip, offset);
|
||||||
|
}
|
||||||
|
Mnemonic::CALL_Mod(_) => todo!(),
|
||||||
|
Mnemonic::CALL_Mp(_) => todo!(),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test
|
* Test
|
||||||
|
|||||||
@@ -110,6 +110,16 @@ impl From<Word> for ImmediateOperand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<usize> for ImmediateOperand {
|
||||||
|
fn from(value: usize) -> Self {
|
||||||
|
if value > Word::MAX as usize {
|
||||||
|
panic!("Cannot convert usize to ImmediateOperand::Word")
|
||||||
|
} else {
|
||||||
|
ImmediateOperand::Word(value as Word)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Into<Word> for ImmediateOperand {
|
impl Into<Word> for ImmediateOperand {
|
||||||
fn into(self) -> u16 {
|
fn into(self) -> u16 {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
Reference in New Issue
Block a user