|
|
@@ -47,6 +47,7 @@ impl<'a> Assembler<'a> { |
|
|
|
// cases that like, actually make sense to process |
|
|
|
Token::Load => machine_code.push(self.load()?), |
|
|
|
Token::Add => machine_code.push(self.add()?), |
|
|
|
Token::Sub => machine_code.push(self.sub()?), |
|
|
|
// cases that should straight up not happen |
|
|
|
_ => return Err(CeresAsmError::LazyBadToken { token }), |
|
|
|
} |
|
|
@@ -91,6 +92,20 @@ impl<'a> Assembler<'a> { |
|
|
|
|
|
|
|
Ok((opcode << 27) | (source_one << 8) | (source_two << 4) | dest) |
|
|
|
} |
|
|
|
|
|
|
|
// sub instruction assembly |
|
|
|
fn sub(&mut self) -> Result<u32> { |
|
|
|
let opcode = 0b00011u32; |
|
|
|
|
|
|
|
let token = self.next()?; |
|
|
|
let source_one = token.register_index()? as u32; |
|
|
|
let token = self.next()?; |
|
|
|
let source_two = token.register_index()? as u32; |
|
|
|
let token = self.next()?; |
|
|
|
let dest = token.register_index()? as u32; |
|
|
|
|
|
|
|
Ok((opcode << 27) | (source_one << 8) | (source_two << 4) | dest) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// assembled machine code |
|
|
@@ -196,6 +211,8 @@ pub enum Token { |
|
|
|
Load, |
|
|
|
#[token("add")] |
|
|
|
Add, |
|
|
|
#[token("sub")] |
|
|
|
Sub, |
|
|
|
|
|
|
|
// logos error |
|
|
|
#[error] |
|
|
@@ -233,6 +250,7 @@ impl Token { |
|
|
|
// instructions |
|
|
|
Self::Load => "ld:".to_owned(), |
|
|
|
Self::Add => "add".to_owned(), |
|
|
|
Self::Sub => "sub".to_owned(), |
|
|
|
// errors |
|
|
|
Self::Error => "ERR".to_owned(), |
|
|
|
} |
|
|
|