implement call, ret, far jumps, add, sub
This commit is contained in:
@@ -50,6 +50,12 @@ impl From<u64> for Addr {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for Addr {
|
||||
fn from(n: usize) -> Self {
|
||||
Self(n as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Addr> for u64 {
|
||||
fn from(addr: Addr) -> Self {
|
||||
addr.0
|
||||
@@ -92,7 +98,7 @@ impl From<String> for Label {
|
||||
}
|
||||
|
||||
/// Routine name
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct RoutineName(pub String);
|
||||
|
||||
impl Display for RoutineName {
|
||||
|
||||
+18
-2
@@ -53,10 +53,26 @@ pub enum Op {
|
||||
/// Compare two values and set conditional flags.
|
||||
/// If the values are identical, evaluate if they are zero, positive, or negative (the "tst" op)
|
||||
Cmp(Rd, Rd),
|
||||
// Increment a value
|
||||
|
||||
// Arithmetic
|
||||
Inc(Wr),
|
||||
// Decrement a value
|
||||
Dec(Wr),
|
||||
Add(Wr, Rd),
|
||||
Sub(Wr, Rd),
|
||||
Mul(Wr, Rd),
|
||||
Div(Wr, Rd),
|
||||
Mod(Wr, /*rem*/Wr, Rd),
|
||||
|
||||
// /// Bitwise
|
||||
And(Wr, Rd),
|
||||
Or(Wr, Rd),
|
||||
Xor(Wr, Rd),
|
||||
Cpl(Wr),
|
||||
Rol(Wr, Rd), // Rotate (with wrap-around)
|
||||
Ror(Wr, Rd),
|
||||
Lsl(Wr, Rd), // Shift
|
||||
Lsr(Wr, Rd),
|
||||
Asr(Wr, Rd),
|
||||
|
||||
// TODO arithmetics, bit manipulation, byte operations
|
||||
}
|
||||
|
||||
@@ -101,6 +101,104 @@ pub fn parse_op(keyword: &str, far : bool, mut arg_tokens: impl Iterator<Item=Se
|
||||
))
|
||||
}
|
||||
|
||||
"add" => {
|
||||
HLOp::L(Op::Add(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"sub" => {
|
||||
HLOp::L(Op::Sub(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"mul" => {
|
||||
HLOp::L(Op::Mul(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"div" => {
|
||||
HLOp::L(Op::Div(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"mod" => {
|
||||
HLOp::L(Op::Mod(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"and" => {
|
||||
HLOp::L(Op::And(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"or" => {
|
||||
HLOp::L(Op::Or(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"xor" => {
|
||||
HLOp::L(Op::Xor(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"cpl" => {
|
||||
HLOp::L(Op::Cpl(
|
||||
parse_wr(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"rol" => {
|
||||
HLOp::L(Op::Rol(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"ror" => {
|
||||
HLOp::L(Op::Ror(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"lsl" | "asl" => {
|
||||
HLOp::L(Op::Lsl(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"lsr" => {
|
||||
HLOp::L(Op::Lsr(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
"asr" => {
|
||||
HLOp::L(Op::Asr(
|
||||
parse_wr(arg_tokens.next())?,
|
||||
parse_rd(arg_tokens.next())?
|
||||
))
|
||||
}
|
||||
|
||||
// TODO more instructions
|
||||
|
||||
other => {
|
||||
|
||||
Reference in New Issue
Block a user