registers.h
This commit is contained in:
parent
51ef24bb53
commit
fe6d690251
@ -20,18 +20,6 @@ str ArgumentType_toString(ArgumentType t){
|
|||||||
return _ArgumentType_str[t];
|
return _ArgumentType_str[t];
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterCode RegisterCode_parse(str r){
|
|
||||||
if(str_equals(r, STR("ax")))
|
|
||||||
return RegisterCode_ax;
|
|
||||||
if(str_equals(r, STR("bx")))
|
|
||||||
return RegisterCode_bx;
|
|
||||||
if(str_equals(r, STR("cx")))
|
|
||||||
return RegisterCode_cx;
|
|
||||||
if(str_equals(r, STR("dx")))
|
|
||||||
return RegisterCode_dx;
|
|
||||||
return RegisterCode_Unset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Section_init(Section* sec, str name){
|
void Section_init(Section* sec, str name){
|
||||||
sec->name = name;
|
sec->name = name;
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#include "../std.h"
|
#include "../std.h"
|
||||||
#include "../string/str.h"
|
#include "../string/str.h"
|
||||||
#include "../instructions/instructions.h"
|
#include "../instructions/instructions.h"
|
||||||
|
#include "../instructions/registers.h"
|
||||||
#include "../collections/List.h"
|
#include "../collections/List.h"
|
||||||
|
|
||||||
typedef enum ArgumentType {
|
typedef enum ArgumentType {
|
||||||
@ -15,16 +16,6 @@ typedef enum ArgumentType {
|
|||||||
|
|
||||||
str ArgumentType_toString(ArgumentType t);
|
str ArgumentType_toString(ArgumentType t);
|
||||||
|
|
||||||
typedef enum RegisterCode {
|
|
||||||
RegisterCode_Unset,
|
|
||||||
RegisterCode_ax,
|
|
||||||
RegisterCode_bx,
|
|
||||||
RegisterCode_cx,
|
|
||||||
RegisterCode_dx
|
|
||||||
} RegisterCode;
|
|
||||||
|
|
||||||
RegisterCode RegisterCode_parse(str register_name);
|
|
||||||
|
|
||||||
typedef struct Argument {
|
typedef struct Argument {
|
||||||
ArgumentType type;
|
ArgumentType type;
|
||||||
union {
|
union {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../instructions.h"
|
#include "../instructions.h"
|
||||||
|
#include "../registers.h"
|
||||||
|
|
||||||
#define readVar(VAR) {\
|
#define readVar(VAR) {\
|
||||||
if(!VM_dataRead(vm, &VAR, vm->current_pos, sizeof(VAR))) \
|
if(!VM_dataRead(vm, &VAR, vm->current_pos, sizeof(VAR))) \
|
||||||
@ -8,7 +9,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define validateRegisterIndex(VAR) {\
|
#define validateRegisterIndex(VAR) {\
|
||||||
if(VAR > sizeof(vm->registers)){\
|
if(VAR> sizeof(vm->registers)){\
|
||||||
VM_setError(vm, "invalid register index (%x)", VAR);\
|
VM_setError(vm, "invalid register index (%x)", VAR);\
|
||||||
return -1;\
|
return -1;\
|
||||||
}\
|
}\
|
||||||
@ -16,6 +17,7 @@
|
|||||||
|
|
||||||
#define readRegisterVar(VAR) {\
|
#define readRegisterVar(VAR) {\
|
||||||
readVar(VAR);\
|
readVar(VAR);\
|
||||||
|
VAR -= 1;\
|
||||||
validateRegisterIndex(VAR);\
|
validateRegisterIndex(VAR);\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/instructions/registers.c
Normal file
13
src/instructions/registers.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "registers.h"
|
||||||
|
|
||||||
|
RegisterCode RegisterCode_parse(str r){
|
||||||
|
if(str_equals(r, STR("ax")))
|
||||||
|
return RegisterCode_ax;
|
||||||
|
if(str_equals(r, STR("bx")))
|
||||||
|
return RegisterCode_bx;
|
||||||
|
if(str_equals(r, STR("cx")))
|
||||||
|
return RegisterCode_cx;
|
||||||
|
if(str_equals(r, STR("dx")))
|
||||||
|
return RegisterCode_dx;
|
||||||
|
return RegisterCode_Unset;
|
||||||
|
}
|
||||||
13
src/instructions/registers.h
Normal file
13
src/instructions/registers.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../std.h"
|
||||||
|
#include "../string/str.h"
|
||||||
|
|
||||||
|
typedef enum RegisterCode {
|
||||||
|
RegisterCode_Unset,
|
||||||
|
RegisterCode_ax,
|
||||||
|
RegisterCode_bx,
|
||||||
|
RegisterCode_cx,
|
||||||
|
RegisterCode_dx
|
||||||
|
} RegisterCode;
|
||||||
|
|
||||||
|
RegisterCode RegisterCode_parse(str register_name);
|
||||||
Loading…
Reference in New Issue
Block a user