diff --git a/EXAMPLES.md b/EXAMPLES.md index 9a9d972..e1b49c1 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -57,4 +57,105 @@ main: ; Метка main swap word ; Блок размером в 2 байта push byte 0x00 ; Дескриптор syscall ; Системный вызов +``` +## Запрос ввода у пользователя +```asm +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/example.asm b/examples/example.asm similarity index 100% rename from example.asm rename to examples/example.asm diff --git a/hello.asm b/examples/hello.asm similarity index 100% rename from hello.asm rename to examples/hello.asm diff --git a/hello_user.asm b/examples/hello_user.asm similarity index 100% rename from hello_user.asm rename to examples/hello_user.asm diff --git a/hello_world.hex b/examples/hello_world.hex similarity index 100% rename from hello_world.hex rename to examples/hello_world.hex diff --git a/input.asm b/examples/input.asm similarity index 100% rename from input.asm rename to examples/input.asm diff --git a/loop.asm b/examples/loop.asm similarity index 100% rename from loop.asm rename to examples/loop.asm diff --git a/set_mov.asm b/examples/set_mov.asm similarity index 100% rename from set_mov.asm rename to examples/set_mov.asm diff --git a/swap.asm b/examples/swap.asm similarity index 100% rename from swap.asm rename to examples/swap.asm diff --git a/wait.asm b/examples/wait.asm similarity index 100% rename from wait.asm rename to examples/wait.asm diff --git a/hello.exe b/hello.exe deleted file mode 100644 index 65b9e18..0000000 Binary files a/hello.exe and /dev/null differ diff --git a/hello_user.exe b/hello_user.exe deleted file mode 100644 index 66b3123..0000000 Binary files a/hello_user.exe and /dev/null differ diff --git a/hello_world.exe b/hello_world.exe deleted file mode 100644 index 7d306c6..0000000 Binary files a/hello_world.exe and /dev/null differ diff --git a/input.exe b/input.exe deleted file mode 100644 index a21e1d7..0000000 Binary files a/input.exe and /dev/null differ diff --git a/project_files/.view.ini b/project_files/.view.ini new file mode 100644 index 0000000..8064423 --- /dev/null +++ b/project_files/.view.ini @@ -0,0 +1,4 @@ +[git] +files= +names= +info=None files diff --git a/project_files/example.txt b/project_files/example.txt deleted file mode 100644 index 3848d38..0000000 --- a/project_files/example.txt +++ /dev/null @@ -1,8 +0,0 @@ -Lorem ipsum dolor sit amet, consectetur -adipiscing elit, sed do eiusmod tempor incididunt ut -labore et dolore magna aliqua. Ut enim ad minim veniam, -quis nostrud exercitation ullamco laboris nisi ut -aliquip ex ea commodo consequat. Duis aute irure dolor -in reprehenderit in voluptate velit esse cillum dolore -eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, -sunt in culpa qui officia deserunt mollit anim id est laborum diff --git a/set_mov.exe b/set_mov.exe deleted file mode 100644 index fa405f6..0000000 Binary files a/set_mov.exe and /dev/null differ diff --git a/swap.exe b/swap.exe deleted file mode 100644 index 77107b3..0000000 Binary files a/swap.exe and /dev/null differ diff --git a/wait.exe b/wait.exe deleted file mode 100644 index ab3d3f6..0000000 Binary files a/wait.exe and /dev/null differ