diff --git a/EXAMPLES.md b/EXAMPLES.md new file mode 100644 index 0000000..74239ff --- /dev/null +++ b/EXAMPLES.md @@ -0,0 +1,22 @@ +# Примеры на ассемблере NTSYS +Это небольшой набор примеров для ассемблера NTSYS. +## Hello, world! +```asm +main: ; Метка main + push.string "Hello, world!\n" ; Записываем строку + push byte, 0x00 ; Запись номера SYSCALL + syscall ; Системный вызов +``` +## Читаем имя пользователя +```asm +main: + push.string "Введите ваше имя: " ; Строка + push byte, 0x00 + syscall +getch: + push db getch + push byte, 0x01 + syscall + push byte, 0x0A + neq byte +``` \ No newline at end of file diff --git a/asm-savers.h b/asm-savers.h index 3dce9ff..62e85ba 100644 --- a/asm-savers.h +++ b/asm-savers.h @@ -74,8 +74,9 @@ static void __str_slice(char* str) { char* ntsys_get_arg(ntsys_asm_cache_t save) { char* str = save->cache; + printf("Cache : %s\n", save->cache); while (1) { - if (!is_space(str[0]) || str[0] == '\0') { + if ((!is_space(str[0])) || str[0] == '\0') { break; } str ++; @@ -90,9 +91,12 @@ char* ntsys_get_arg(ntsys_asm_cache_t save) { } n_p ++; } - save->cache = &str[n_p + 1]; + byte_t t = 1; + if (n_p + t > strlen(str)) t = 0; + save->cache = &str[n_p + t]; str[n_p] = '\0'; } + printf("Switch : %s\n", save->cache); if (str[strlen(str) - 1] == '\n' || str[strlen(str) - 1] == '\r') str[strlen(str) - 1] = '\0'; if (strlen(str) == 0) { str = NULL; @@ -134,6 +138,7 @@ char* ntsys_get_arg(ntsys_asm_cache_t save) { } } save->string = str; + printf("Loading : %s\n", str); return str; } diff --git a/dump.bin b/dump.bin index 0d2b7c6..cf6abf9 100644 Binary files a/dump.bin and b/dump.bin differ diff --git a/example.asm b/example.asm index b977192..72a4c97 100644 --- a/example.asm +++ b/example.asm @@ -1,4 +1,4 @@ main: ; Метка main push.string "Hello, world!\n" ; Записываем строку - push byte, 0x00 ; Запись номера SYSCALL + push byte 0x00 ; Запись номера SYSCALL syscall ; Системный вызов \ No newline at end of file diff --git a/input.asm b/input.asm new file mode 100644 index 0000000..74d2d3a --- /dev/null +++ b/input.asm @@ -0,0 +1,10 @@ +main: + push.string "Введите ваше имя: " ; Строка + push byte 0x00 + syscall +getch: + push db getch + push byte 0x01 + syscall + push byte 0x0A + neq byte diff --git a/input.exe b/input.exe new file mode 100644 index 0000000..65b9e18 Binary files /dev/null and b/input.exe differ diff --git a/ntfiles.h b/ntfiles.h index 6fea630..62b5336 100644 --- a/ntfiles.h +++ b/ntfiles.h @@ -587,6 +587,8 @@ static void nt_fs_syscall(void) { case 0x00: { fputs((char*)stack + sp, stdout); + size_t len = strlen((char*)stack + sp); + sp += len; } break; case 0x01: @@ -601,6 +603,14 @@ static void nt_fs_syscall(void) { cnt = __ntsys_buffer_size - 1; } break; + case 0x03: + { + if ((fGH6VSEzu7qNiGVE_stat = system((char*)stack + sp)) != EXIT_SUCCESS) + cnt = __ntsys_buffer_size - 1; + size_t len = strlen((char*)stack + sp); + sp += len; + } + break; } } diff --git a/ntsys b/ntsys index e14ff67..58fd453 100755 Binary files a/ntsys and b/ntsys differ