diff --git a/BINCOM.md b/BINCOM.md index ac92ad3..8a5a5df 100644 --- a/BINCOM.md +++ b/BINCOM.md @@ -98,4 +98,6 @@ > main: > ; Точка входа > ``` -- **GLOBAL** - Ассемблерная инструкция, означает метку для старта. \ No newline at end of file +- **GLOBAL** - Ассемблерная инструкция, означает метку для старта. +- **EXIT** - Ассемблерная инструкция, означает немедленное завершение программы. +- **RCALL** - Ассемблерная инструкция, означает вызов функции (```rcall тип имя```). \ No newline at end of file diff --git a/OPTIONS.md b/OPTIONS.md index b5d40dd..e5a0346 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -5,6 +5,7 @@ - ```--out / -o - set output file name``` - ```--debug / -d - display debugging info``` - ```--mem / -m - asm output memory size``` +- ```--nfull / -n - no print all debug info``` ## Опция HELP Может быть вызвана как ```--help``` или ```-h```. Эта опция выводит краткую справку. @@ -23,4 +24,7 @@ ## Опция MEM Может быть вызвана как ```--mem``` или ```-m```. Эта опция меняет размер памяти, выделяймой под программу при компиляции ассемблера. -Рекомендуется к использованию всегда. \ No newline at end of file +Рекомендуется к использованию всегда. +## Опция NFULL +Может быть вызвана как ```--nfull``` или ```-n```. +Эта опция выключаеть вывод аддресов и запрос выполнения в [режиме отладки](#опция-debug). \ No newline at end of file diff --git a/dump.bin b/dump.bin index 81c3067..9618b3a 100644 Binary files a/dump.bin and b/dump.bin differ diff --git a/hello_user.asm b/hello_user.asm new file mode 100644 index 0000000..2209f25 --- /dev/null +++ b/hello_user.asm @@ -0,0 +1,98 @@ +global db main ; Точка входа + +readmem: ; Функция чтения из памяти + push dw 0x00 ; Адрес + mread dw ; Читаем + ret ; Конец функции + +insub: ; Уменьшение адреса + push dw 1 ; На сколько уменьшать + push byte 2 ; Поменять два места + swap dw ; Тип данных - size_t + sub dw ; Уменьшить + ret ; Конец функции + +writemem: ; Функция записи в память + push dw 0x00 ; Адрес + mwrt dw ; Записываем + ret ; Конец функции + +decrement: ; Управление данными + rcall db readmem ; Прочитать + rcall db insub ; Уменьшить + rcall db writemem ; Записать + ret ; Конец функции + +main: ; Точка входа + push.string "Введите ваше имя: " ; Строка + push byte 0x00 ; Дескриптор + syscall ; Выводим + +begin: ; Настройка адресов + push dw 0x02 ; Указатель + push dw 0x00 ; Адрес + mwrt dw ; Записываем + +inloop: ; Цикл чтения символов + push byte 0x01 ; Дескриптор + syscall ; Читаем + copy byte ; Копируем char + + push dw 0x00 ; Адрес + mread dw ; Читаем + + mwrt byte ; Записываем + + push dw 0x00 ; Читаем + mread dw ; Указатель + + push dw 0x01 ; Увеличить + add dw ; На 1 + + push dw 0x00 ; Адрес + mwrt word ; Сохраняем указатель + + push byte 0x0A ; Символ переноса + push db inloop ; Цикл + push byte 2 ; Кол-во слов + swap word ; Меняем их местами + neq byte ; Если не \n - повторить цикл + +userhello: ; Приветствие + push.string "Привет, " ; Текст + push byte 0x00 ; Дескриптор + syscall ; Выводим + rcall db decrement ; Уменьшаем + push byte 0x00 ; Символ конца строки + +readcycle: ; Цикл чтения + push db writeusername ; Конец цикла + push dw 0x00 ; Адрес + mread dw ; Указатель + push dw 0x01 ; Число + eq dw ; Если равно - выйти + + push db rdecrem ; Адрес + + push dw 0x00 ; Иначе + mread dw ; Читаем указатель + mread byte ; Читаем байт по указателю + + push byte 0x0A ; Если символ переноса + eq byte ; Пропускаем добавление на стек + + push dw 0x00 ; Иначе + mread dw ; Читаем указатель + mread byte ; Читаем байт по указателю + +rdecrem: ; Уменьшение указателя + rcall db decrement ; Уменьшаем + push db readcycle ; Указатель на цикл + jmp ; Повторить цикл + +writeusername: ; Выводим имя + push byte 0x00 ; Дескриптор + syscall ; Выводим + push.string "!\n" ; Выводим ! + push byte 0x00 ; Дескриптор + syscall ; Выводим \ No newline at end of file diff --git a/hello_user.exe b/hello_user.exe new file mode 100644 index 0000000..66b3123 Binary files /dev/null and b/hello_user.exe differ diff --git a/ntfiles.h b/ntfiles.h index 70f1e46..5d65a08 100644 --- a/ntfiles.h +++ b/ntfiles.h @@ -583,6 +583,7 @@ static byte_t get_pop_sp_byte(void) { } static void nt_fs_syscall(void) { + /* printf("\nStack point %d 0x%X\n", __ntsys_stack_pointer, __ntsys_stack_pointer); */ switch (get_pop_sp_byte()) { case 0x00: { @@ -600,7 +601,7 @@ static void nt_fs_syscall(void) { case 0x02: { fGH6VSEzu7qNiGVE_stat = get_pop_sp_word(); - cnt = __ntsys_buffer_size - 1; + cnt = __ntsys_buffer_size; } break; case 0x03: @@ -623,6 +624,7 @@ static void nt_fs_syscall(void) { } break; } + /* printf("\nStack point %d 0x%X\n", __ntsys_stack_pointer, __ntsys_stack_pointer); */ } static void stack_swap(void) { diff --git a/ntsys b/ntsys index cc1a2a7..c8509ba 100755 Binary files a/ntsys and b/ntsys differ diff --git a/ntsys-assembler.h b/ntsys-assembler.h index e365a61..0e86690 100644 --- a/ntsys-assembler.h +++ b/ntsys-assembler.h @@ -12,7 +12,7 @@ * XX - шестнадцатиричные данные */ -const size_t ntsys_command_count = 0x23; +const size_t ntsys_command_count = 0x26; char* ntsys_asm_table[] = { "push=00:T:D", @@ -52,11 +52,15 @@ char* ntsys_asm_table[] = { "swap=1B:T", "dup=1C:T", + "copy=1C:T", "set=1D", "mov=1E", "global=00:T:D0D", + "exit=000200000001021A", + "rcall=00:T:D1F", + "call=1F", "ret=20", diff --git a/ntsys.h b/ntsys.h index 6577ea3..470f77e 100644 --- a/ntsys.h +++ b/ntsys.h @@ -85,10 +85,11 @@ static void __help(void) { " " "--asm / -a - compile assembler program" "\n" " " "--out / -o - set output file name" "\n" " " "--debug / -d - display debugging info" "\n" - " " "--mem / -m - asm output memory size" "\0" + " " "--mem / -m - asm output memory size" "\n" + " " "--nfull / -n - no print all debug info" "\0" ); } -static int __exe_run(__e_byte_t* memory, unsigned int memorysize, unsigned long filesize, FILE* fp, __e_byte_t debug) { +static int __exe_run(__e_byte_t* memory, __e_byte_t fulldebug, unsigned int memorysize, unsigned long filesize, FILE* fp, __e_byte_t debug) { __ntsys_stack_pointer = memorysize; __ntsys_stack = memory; __e_byte_t* buff = malloc(filesize - 8); @@ -105,12 +106,14 @@ static int __exe_run(__e_byte_t* memory, unsigned int memorysize, unsigned long putchar('\n'); while (__ntsys_buffer_ptr < __ntsys_buffer_size) { __e_byte_t cmd = buff[__ntsys_buffer_ptr]; - fprintf(stdout, "Command %d 0x%X\n" - "Position %d 0x%X\n" - "Stack point %d 0x%X\n\n" - , cmd, cmd, - __ntsys_buffer_ptr, __ntsys_buffer_ptr, - __ntsys_stack_pointer, __ntsys_stack_pointer); + if (fulldebug) { + fprintf(stdout, "Command %d 0x%X\n" + "Position %d 0x%X\n" + "Stack point %d 0x%X\n\n" + , cmd, cmd, + __ntsys_buffer_ptr, __ntsys_buffer_ptr, + __ntsys_stack_pointer, __ntsys_stack_pointer); + } __ntsys_buffer_ptr ++; fn_fGH6VSEzu7qNiGVE[cmd](); FILE* df = fopen("dump.bin", "wb"); @@ -120,16 +123,21 @@ static int __exe_run(__e_byte_t* memory, unsigned int memorysize, unsigned long } fwrite(__ntsys_stack, 1, memorysize, df); fclose(df); - puts("Press any key to continue..."); - getchar(); + if (fulldebug) { + puts("Press any key to continue..."); + getchar(); + } } } + if (debug) { + printf("\nStack point %d 0x%X\n", __ntsys_stack_pointer, __ntsys_stack_pointer); + } free(buff); if (fGH6VSEzu7qNiGVE_stat != EXIT_SUCCESS) return fGH6VSEzu7qNiGVE_stat; return EXIT_SUCCESS; } -int ntsys_api_call(char* filename, unsigned char debug) { +int ntsys_api_call(char* filename, unsigned char debug, unsigned char isFullDebug) { /* File data */ @@ -193,7 +201,7 @@ int ntsys_api_call(char* filename, unsigned char debug) { printf("File size %lu 0x%lX\n", filesize, filesize); printf("Memory size %u 0x%X\n", mem_size, mem_size); } - int stat = __exe_run(memory, mem_size, filesize, fp, debug); + int stat = __exe_run(memory, isFullDebug, mem_size, filesize, fp, debug); fclose(fp); free(memory); return stat; @@ -206,6 +214,7 @@ int _lib_ntsys_main(int argc, char** argv) { char mode = 'R'; unsigned char out = 0; unsigned char debug = 0; + unsigned char is_full_deb = 1; unsigned char mem = 0; while (t < argc) { char* str = argv[t]; @@ -216,6 +225,10 @@ int _lib_ntsys_main(int argc, char** argv) { case 'd': debug = 1; break; + case 'n': + debug = 1; + is_full_deb = 0; + break; case 'h': __help(); return EXIT_SUCCESS; @@ -254,7 +267,7 @@ int _lib_ntsys_main(int argc, char** argv) { ntsys_error("Please specify the file name!"); return EXIT_FAILURE; } - if (mode == 'R') return ntsys_api_call(filename, debug); + if (mode == 'R') return ntsys_api_call(filename, debug, is_full_deb); return ntsys_compile_asm(filename, asm_out); }