Compare commits

..

No commits in common. "d1d45fb708df527aca14743ff161f29c310e9204" and "543766bad1a0dbec4eaebe296629625ec340f43f" have entirely different histories.

5 changed files with 29 additions and 31 deletions

View File

@ -138,7 +138,7 @@ char* ntsys_get_arg(ntsys_asm_cache_t save) {
}
}
save->string = str;
printf("Loading : %s\n", save->string);
printf("Loading : %s\n", str);
return str;
}
@ -402,6 +402,7 @@ int __ntsys_arg_function_loader(ntsys_argument_parser_t* parser) {
if (select_argument(parser) == EXIT_FAILURE) return EXIT_FAILURE;
}
if (parser->is_rewrite == 0) *parser->file_size = ftell(parser->fp) + 1;
fflush(parser->fp);
return EXIT_SUCCESS;
}

View File

@ -1,4 +1,4 @@
main: ; Метка main
push.string "Hello, world!\n" ; Записываем строку
push byte 0x00 ; Запись номера SYSCALL
push byte 0x00 ; Запись номера SYSCALL
syscall ; Системный вызов

BIN
example.exe Normal file

Binary file not shown.

BIN
ntsys

Binary file not shown.

View File

@ -64,6 +64,13 @@ int ntsys_compile_asm(char* filename, char* asm_out) {
ntsys_error("Cannot open assembler file!");
return EXIT_FAILURE;
}
FILE* fw = fopen(asm_out, "wb");
FILE* tmp = tmpfile();
if (fw == NULL || tmp == NULL) {
ntsys_error("Cannot create or rewrite output file!");
fclose(fp);
return EXIT_FAILURE;
}
char* st = NULL;
size_t mem_pos = 0;
size_t lb_size = 0;
@ -87,40 +94,11 @@ int ntsys_compile_asm(char* filename, char* asm_out) {
rewind(fp);
size_t labels_count = 0;
dword_t fsz = 0;
FILE* tmp = tmpfile();
if (tmp == NULL) {
ntsys_error("Cannot create or rewrite output file!");
fclose(fp);
return EXIT_FAILURE;
}
while ((st = ntsys_get_str(st, fp)) != NULL) {
if (ntsys_asm_from_string(&mem_pos, st, tmp, 0, labels, labels_pos, &labels_count, &fsz) != EXIT_SUCCESS) {
free(st);
fclose(fp);
fclose(tmp);
size_t i = 0;
while (i < lb_size) {
if (labels[i] != NULL) free(labels[i]);
i ++;
}
free(labels);
free(labels_pos);
return EXIT_FAILURE;
}
}
free(st);
fclose(tmp);
rewind(fp);
FILE* fw = fopen(asm_out, "wb");
if (fw == NULL) {
ntsys_error("Cannot create or rewrite output file!");
fclose(fp);
return EXIT_FAILURE;
}
while ((st = ntsys_get_str(st, fp)) != NULL) {
if (ntsys_asm_from_string(&mem_pos, st, fw, 1, labels, labels_pos, &labels_count, &fsz) != EXIT_SUCCESS) {
free(st);
fclose(fp);
fclose(fw);
size_t i = 0;
while (i < lb_size) {
@ -132,6 +110,25 @@ int ntsys_compile_asm(char* filename, char* asm_out) {
return EXIT_FAILURE;
}
}
free(st);
rewind(fp);
while ((st = ntsys_get_str(st, fp)) != NULL) {
if (ntsys_asm_from_string(&mem_pos, st, fw, 1, labels, labels_pos, &labels_count, &fsz) != EXIT_SUCCESS) {
free(st);
fclose(fp);
fclose(tmp);
fclose(fw);
size_t i = 0;
while (i < lb_size) {
if (labels[i] != NULL) free(labels[i]);
i ++;
}
free(labels);
free(labels_pos);
return EXIT_FAILURE;
}
}
fclose(tmp);
fflush(fw);
free(st);
fclose(fp);