Skip to content

Commit e6019db

Browse files
committed
Handle no space between instruction arguments
1 parent 69e873d commit e6019db

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/assembler/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub enum Token {
2828

2929
pub fn translate_line(line: &str) -> Result<Vec<MaybeUnresolvedInstr>> {
3030
let (instruction, comment) = line.split_once(';').unwrap();
31+
// The UNCA examples don't use spaces between instruction args, so we should always just add a
32+
// space after a comma to make sure we're able to parse properly
33+
let instruction = instruction.replace(',', ", ");
3134
let splits = instruction.split_ascii_whitespace();
3235
let mut token_chain: Vec<Token> = Vec::new();
3336

@@ -58,4 +61,13 @@ mod test {
5861
assert_eq!(machine_code.len(), 1);
5962
assert_eq!(machine_code.first().unwrap().value, 0b0101000001000000);
6063
}
64+
65+
#[test]
66+
fn translate_instr_no_space() {
67+
let instruction: &str = "AND R0,R1,R0;";
68+
let machine_code = translate_line(instruction).unwrap();
69+
70+
assert_eq!(machine_code.len(), 1);
71+
assert_eq!(machine_code.first().unwrap().value, 0b0101000001000000);
72+
}
6173
}

0 commit comments

Comments
 (0)