ft(interpreter): impl basic call

This commit is contained in:
2025-06-17 11:24:03 +09:00
parent 7e7e648fa8
commit 200640447b
3 changed files with 28 additions and 7 deletions

View File

@@ -202,14 +202,14 @@ pub enum Mnemonic {
CBW,
CWD,
// CALL
CALL_p(Pointer32),
CALL_v(usize),
CALL_Mod(ModRmTarget),
CALL_Mp(Pointer16),
CALL_p(Pointer32), // 0x9A
CALL_v(usize), // 0xE8
CALL_Mod(ModRmTarget), // 0xFF 2
CALL_Mp(Pointer16), // 0xFF 3
// JUMP
JMP_p(Pointer32),
JMP_b(usize), // parses IByte, but stores as isize
JMP_v(usize), // parwses IWord, but stores as isize
JMP_b(usize),
JMP_v(usize),
JMP_Mod(ModRmTarget),
JMP_Mp(Pointer16),
// WAIT

View File

@@ -1,5 +1,5 @@
use core::fmt;
use std::{fmt::Debug, process::exit};
use std::{env::current_dir, fmt::Debug, process::exit};
use crate::{
instructions::{Instruction, Mnemonic},
@@ -413,6 +413,17 @@ impl Interpreter {
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

View File

@@ -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 {
fn into(self) -> u16 {
match self {