Data types

This commit is contained in:
german 2026-03-05 17:42:19 +04:00
parent 3dc3af8eba
commit a5f7f103c0
3 changed files with 91 additions and 6 deletions

View File

@ -1,8 +1,9 @@
#if (!defined(NTSYS__S_ASSEMBLER_H___))
#define NTSYS__S_ASSEMBLER_H___
#define ntsys_exit_if_error(parser) if (!ntsys_asm_arg_new((parser)->string, (parser)->cache))
#define ntsys_run_asm_parser(ss) __ntsys_arg_function_loader(&(ss))
#define create_ntsys_asm_parser(cache, fp, str, table, table_size, labels) ((ntsys_argument_parser_t){(cache), (fp), (str), (table), (table_size), (labels), (labels)})
#define create_ntsys_asm_parser(cache, fp, str, table, table_size, labels) ((ntsys_argument_parser_t){(cache), (fp), (str), (table), (table_size), (labels)})
#define create_ntsys_asm_save(ss) ((ntsys_asm_save_t){(ss), (ss)})
#define create_ntsys_asm_cache(ss) ((ntsys_asm_cache_t)&(ss))
#define ntsys_asm_arg_new(str, __cache) ((ntsys_get_arg((__cache))) && ((str) = __cache->string))
@ -138,11 +139,91 @@ typedef struct {
} ntsys_argument_parser_t;
static void __input_datatype(ntsys_argument_parser_t* parser, byte_t* mode) {
ntsys_exit_if_error(parser) {
ntsys_error("Cannot find argument!");
return;
}
byte_t data_type = 0x01;
char* str = parser->string;
if (strcmp(str, "byte") == 0) {
data_type = 0x01;
} else if (strcmp(str, "word") == 0) {
data_type = 0x02;
} else if (strcmp(str, "dword") == 0) {
data_type = 0x04;
} else if (strcmp(str, "qword") == 0) {
data_type = 0x08;
} else if (strcmp(str, "sbyte") == 0) {
data_type = 0xF1;
} else if (strcmp(str, "sword") == 0) {
data_type = 0xF2;
} else if (strcmp(str, "sdword") == 0) {
data_type = 0xF4;
} else if (strcmp(str, "sqword") == 0) {
data_type = 0xF8;
} else if (strcmp(str, "db") == 0) {
data_type = 0xBC;
} else {
ntsys_error("Incorrect datatype!");
return;
}
if (data_type == 0xBC) fputc((__e_byte_t)0x02, parser->fp);
else fputc((__e_byte_t)data_type, parser->fp);
*mode = data_type;
}
static void __write_label(ntsys_argument_parser_t* parser) {
}
static void __input_data(ntsys_argument_parser_t* parser, byte_t* mode) {
ntsys_exit_if_error(parser) {
ntsys_error("Cannot find argument!");
return;
}
byte_t data_type = *mode;
char* str = parser->string;
if (str[0] >= '0' && str[0] <= '9') {
int count_system = 10;
if (str[1] == 'x') {
count_system = 16;
} else if (str[1] == 'b') {
count_system = 2;
} else {
ntsys_error("Unknown number system!");
return;
}
if (count_system != 10) {
str += 2;
}
long cnt = strtol(str, NULL, count_system);
FILE* fp = parser->fp;
switch (data_type) {
case 0x01: fwrite((__e_byte_t*)((byte_t*)&cnt), 1, sizeof(byte_t), fp);
break;
case 0x02: fwrite((__e_byte_t*)((word_t*)&cnt), 1, sizeof(word_t), fp);
break;
case 0x04: fwrite((__e_byte_t*)((dword_t*)&cnt), 1, sizeof(dword_t), fp);
break;
case 0x08: fwrite((__e_byte_t*)((qword_t*)&cnt), 1, sizeof(qword_t), fp);
break;
case 0xF1: fwrite((__e_byte_t*)((sbyte_t*)&cnt), 1, sizeof(sbyte_t), fp);
break;
case 0xF2: fwrite((__e_byte_t*)((sword_t*)&cnt), 1, sizeof(sword_t), fp);
break;
case 0xF4: fwrite((__e_byte_t*)((sdword_t*)&cnt), 1, sizeof(sdword_t), fp);
break;
case 0xF8: fwrite((__e_byte_t*)((sqword_t*)&cnt), 1, sizeof(sqword_t), fp);
break;
}
} else {
if (data_type != 0xBC) {
ntsys_error("Incorrect datatype! For jump to label please use db type!");
return;
}
__write_label(parser);
}
}
static int __arg_writer(char* str, ntsys_argument_parser_t* parser, byte_t mode) {
@ -159,8 +240,13 @@ static int __arg_writer(char* str, ntsys_argument_parser_t* parser, byte_t mode)
return EXIT_SUCCESS;
}
static int select_argument(char* str, ntsys_argument_parser_t* parser) {
static int select_argument(ntsys_argument_parser_t* parser) {
size_t i = 0;
char* str = parser->string;
if (str[strlen(str) - 1] == ':') {
/* TODO: Добавить метки */
return EXIT_SUCCESS;
}
char buf[64];
char** table = parser->table;
while (i < parser->table_length) {
@ -194,9 +280,8 @@ static int select_argument(char* str, ntsys_argument_parser_t* parser) {
}
int __ntsys_arg_function_loader(ntsys_argument_parser_t* parser) {
char* str = parser->string;
while (ntsys_asm_arg_new(str, parser->cache)) {
if (select_argument(str, parser) == EXIT_FAILURE) return EXIT_FAILURE;
while (ntsys_asm_arg_new(parser->string, parser->cache)) {
if (select_argument(parser) == EXIT_FAILURE) return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

BIN
ntsys

Binary file not shown.

BIN
out.exe

Binary file not shown.