Counting actual instructions

master
Wynd 2024-10-20 13:56:40 +03:00
parent 7f53e13f4f
commit b416a32ee7
1 changed files with 20 additions and 6 deletions

View File

@ -33,38 +33,52 @@ fn main() {
};
match instruction {
b'+' => tape[cell_index] = tape[cell_index].wrapping_add(1),
b'-' => tape[cell_index] = tape[cell_index].wrapping_sub(1),
b'+' => {
tape[cell_index] = tape[cell_index].wrapping_add(1);
icount += 1;
}
b'-' => {
tape[cell_index] = tape[cell_index].wrapping_sub(1);
icount += 1;
}
b'>' => {
cell_index = cell_index.wrapping_add(1);
if tape.len() <= cell_index {
tape.push(0);
}
icount += 1;
}
b'<' => {
cell_index = cell_index.wrapping_sub(1);
icount += 1;
}
b'.' => {
print!("{}", tape[cell_index] as char);
icount += 1;
}
b'<' => cell_index = cell_index.wrapping_sub(1),
b'.' => print!("{}", tape[cell_index] as char),
b',' => {
if user_input.is_empty() {
user_input = input();
}
tape[cell_index] = user_input.remove(0);
icount += 1;
}
b'[' => {
if tape[cell_index] == 0 {
ip = *table.get(&ip).unwrap();
}
icount += 1;
}
b']' => {
if tape[cell_index] != 0 {
ip = *table.get(&ip).unwrap();
}
icount += 1;
}
_ => {}
}
ip += 1;
icount += 1;
}
println!();