jump
This commit is contained in:
40
src/instructions/impl/JMP.c
Normal file
40
src/instructions/impl/JMP.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "impl_macros.h"
|
||||
|
||||
// JUMP [destination address]
|
||||
i32 JMP_impl(VM* vm){
|
||||
u32 dst_addr = 0;
|
||||
readVar(dst_addr);
|
||||
|
||||
vm->current_pos = dst_addr;
|
||||
|
||||
return sizeof(dst_addr);
|
||||
}
|
||||
|
||||
|
||||
// JNZ [destination address] [condition register]
|
||||
i32 JNZ_impl(VM* vm){
|
||||
u32 dst_addr = 0;
|
||||
readVar(dst_addr);
|
||||
u8 cond_register_i = 0;
|
||||
readRegisterVar(cond_register_i);
|
||||
|
||||
if(vm->registers.array[cond_register_i].u32v0 != 0){
|
||||
vm->current_pos = dst_addr;
|
||||
}
|
||||
|
||||
return sizeof(dst_addr) + sizeof(cond_register_i);
|
||||
}
|
||||
|
||||
// JZ [destination address] [condition register]
|
||||
i32 JZ_impl(VM* vm){
|
||||
u32 dst_addr = 0;
|
||||
readVar(dst_addr);
|
||||
u8 cond_register_i = 0;
|
||||
readRegisterVar(cond_register_i);
|
||||
|
||||
if(vm->registers.array[cond_register_i].u32v0 == 0){
|
||||
vm->current_pos = dst_addr;
|
||||
}
|
||||
|
||||
return sizeof(dst_addr) + sizeof(cond_register_i);
|
||||
}
|
||||
@@ -27,8 +27,8 @@ i32 XOR_impl(VM* vm);
|
||||
i32 AND_impl(VM* vm);
|
||||
|
||||
i32 JMP_impl(VM* vm);
|
||||
i32 JIF_impl(VM* vm);
|
||||
i32 JEL_impl(VM* vm);
|
||||
i32 JNZ_impl(VM* vm);
|
||||
i32 JZ_impl(VM* vm);
|
||||
|
||||
|
||||
Array_declare(Instruction);
|
||||
@@ -59,8 +59,8 @@ static const Array_Instruction instructions_array = ARRAY(Instruction, {
|
||||
Instruction_construct(AND),
|
||||
|
||||
Instruction_construct(JMP),
|
||||
Instruction_construct(JIF),
|
||||
Instruction_construct(JEL),
|
||||
Instruction_construct(JNZ),
|
||||
Instruction_construct(JZ),
|
||||
});
|
||||
|
||||
const Instruction* Instruction_getByOpcode(Opcode opcode){
|
||||
|
||||
@@ -32,8 +32,8 @@ typedef enum __attribute__((__packed__)) Opcode {
|
||||
Opcode_AND,
|
||||
|
||||
Opcode_JMP,
|
||||
Opcode_JIF,
|
||||
Opcode_JEL,
|
||||
Opcode_JNZ,
|
||||
Opcode_JZ,
|
||||
} Opcode;
|
||||
|
||||
typedef struct Instruction {
|
||||
|
||||
Reference in New Issue
Block a user