starting work on assembler

This commit is contained in:
SpookyDervish
2025-12-21 09:44:16 +11:00
parent b1ff26bcbb
commit e92f097afe
16 changed files with 315 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
#include "vmbl.h"
#include "file_utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -93,6 +94,9 @@ VMBL_Exception VBML_ExecuteInstruction(VMBL_State *vmblState, VMBL_Instruction i
break;
case INSTRUCTION_NOP:
break;
default:
return (VMBL_Exception) { EXCEPTION_INVALID_OPCODE };
break;
@@ -126,7 +130,7 @@ void VMBL_StartVM(VMBL_State *vmblState) {
VMBL_Instruction instruction = vmblState->program[vmblState->ip++];
printf("%s 0x%lx, 0x%lx, 0x%lx\n", instructionTypeToCStr(instruction.type), instruction.opperands[0], instruction.opperands[1], instruction.opperands[2]);
//printf("%s 0x%lx, 0x%lx, 0x%lx\n", instructionTypeToCStr(instruction.type), instruction.opperands[0], instruction.opperands[1], instruction.opperands[2]);
VMBL_Exception exception = VBML_ExecuteInstruction(vmblState, instruction);
@@ -156,8 +160,8 @@ void VMBL_LoadExecutable(VMBL_State *vmblState, VMBL_Instruction *program, size_
vmblState->programSize = programSize;
}
void VMBL_LoadExecutableFromFile(VMBL_State *vmblState, const char* filePath) {
FILE *file = fopen(filePath, "rb");
void VMBL_LoadExecutableFromFile(VMBL_State *vmblState, char* filePath) {
/*FILE *file = fopen(filePath, "rb");
if (file == NULL) {
perror("VMBL: Failed to open file");
@@ -170,11 +174,13 @@ void VMBL_LoadExecutableFromFile(VMBL_State *vmblState, const char* filePath) {
size_t programSize = size / sizeof(vmblState->program[0]);
VMBL_Instruction program[programSize];
fread(program, sizeof(program[0]), programSize, file);
fread(program, sizeof(program[0]), programSize, file);*/
VMBL_LoadExecutable(vmblState, program, programSize);
VMBL_Instruction *program = (VMBL_Instruction*)readStringFromFile(filePath);
fclose(file);
VMBL_LoadExecutable(vmblState, program, sizeof(program));
//fclose(file);
}