Simple program which assembles instructions then executes them
This commit is contained in:
20
src/main.c
20
src/main.c
@@ -42,19 +42,13 @@ int assemble_instructions(inst_t *instructions, size_t number,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
byte stack_data[256];
|
||||
vm_t vm = {0};
|
||||
vm_load_stack(&vm, stack_data, ARR_SIZE(stack_data));
|
||||
inst_t instructions[] = {
|
||||
INST_BPUSH(0xfa), INST_BMOV(0), INST_BPUSH(0xfb),
|
||||
INST_BMOV(1), INST_BPUSH(0xfc), INST_BMOV(2),
|
||||
INST_BPUSH(0xfd), INST_BMOV(3), INST_BPUSH_REG(3),
|
||||
INST_BPUSH_REG(2), INST_BPUSH_REG(1), INST_BPUSH_REG(0),
|
||||
};
|
||||
vm_load_program(&vm, instructions, ARR_SIZE(instructions));
|
||||
for (size_t i = 0; i < ARR_SIZE(instructions); ++i)
|
||||
vm_execute(&vm);
|
||||
const char *filename = "out.bin";
|
||||
if (argc >= 2)
|
||||
filename = argv[1];
|
||||
inst_t instructions[] = {INST_HALT};
|
||||
assemble_instructions(instructions, ARR_SIZE(instructions), filename);
|
||||
interpret_bytecode(filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user