From 1698b43da627c4a096dff4b0c0e83739a0d20ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=8B=D1=82=D0=BA=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD?= Date: Wed, 24 Sep 2025 02:05:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20wayland?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nasm.code-workspace | 3 ++ ...e-workspace => stepik_base.code-workspace} | 0 wayland/.vscode/launch.json | 37 +++++++++++++++++++ wayland/CMakeLists.txt | 10 +++++ wayland/CMakePresets.json | 25 +++++++++++++ wayland/asm.asm | 23 ++++++++++++ wayland/c.c | 24 ++++++++++++ 7 files changed, 122 insertions(+) rename stepik_base/{nasm.code-workspace => stepik_base.code-workspace} (100%) create mode 100644 wayland/.vscode/launch.json create mode 100644 wayland/CMakeLists.txt create mode 100644 wayland/CMakePresets.json create mode 100644 wayland/asm.asm create mode 100644 wayland/c.c diff --git a/nasm.code-workspace b/nasm.code-workspace index 35a4398..6e8cf42 100644 --- a/nasm.code-workspace +++ b/nasm.code-workspace @@ -3,6 +3,9 @@ { "path": "casm" }, + { + "path": "wayland" + }, { "path": "docs" }, diff --git a/stepik_base/nasm.code-workspace b/stepik_base/stepik_base.code-workspace similarity index 100% rename from stepik_base/nasm.code-workspace rename to stepik_base/stepik_base.code-workspace diff --git a/wayland/.vscode/launch.json b/wayland/.vscode/launch.json new file mode 100644 index 0000000..776c494 --- /dev/null +++ b/wayland/.vscode/launch.json @@ -0,0 +1,37 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "(lldb) Launch", + "type": "lldb", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "args": [], + "cwd": "${workspaceFolder}", + "env": { + "PATH": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" + } + }, + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "cwd": "${workspaceFolder}", + "environment": [ + { + "name": "PATH", + "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" + }, + ], + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + ] + } + ] +} \ No newline at end of file diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt new file mode 100644 index 0000000..32c298e --- /dev/null +++ b/wayland/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.14) + +project(wayland) + +enable_language(ASM_NASM) + +set(CMAKE_ASM_NASM_FLAGS "-f elf64") +set(CMAKE_ASM_NASM_FLAGS_DEBUG "-gdwarf") + +add_executable(wayland asm.asm c.c) \ No newline at end of file diff --git a/wayland/CMakePresets.json b/wayland/CMakePresets.json new file mode 100644 index 0000000..0b9e457 --- /dev/null +++ b/wayland/CMakePresets.json @@ -0,0 +1,25 @@ +{ + "version": 8, + "configurePresets": [ + { + "name": "debug-gcc", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_C_COMPILER": "/usr/bin/gcc", + "CMAKE_CXX_COMPILER": "/usr/bin/g++", + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release-gcc", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_C_COMPILER": "/usr/bin/gcc", + "CMAKE_CXX_COMPILER": "/usr/bin/g++", + "CMAKE_BUILD_TYPE": "Release" + } + } + ] +} \ No newline at end of file diff --git a/wayland/asm.asm b/wayland/asm.asm new file mode 100644 index 0000000..9eac30d --- /dev/null +++ b/wayland/asm.asm @@ -0,0 +1,23 @@ +global main +extern sum, print, scan +extern a + +section .text +main: + push rbx + call scan ; прочитать первое число + mov rbx, rax ; сохранить первое число + call scan ; прочитать второе число + mov rdi, rbx ; a + mov rsi, rax ; b + call sum ; сумма + mov rdi, rax ; результат + push rax + call print ; напечатать + pop rax + pop rbx + + mov dword [rel a], eax ; записать значение 42 в переменную a + + mov rax, 0 + ret \ No newline at end of file diff --git a/wayland/c.c b/wayland/c.c new file mode 100644 index 0000000..f90fb1c --- /dev/null +++ b/wayland/c.c @@ -0,0 +1,24 @@ +#include +#include + +int a; + +int sum(int a, int b) { + return a+b; +} + +void print(int num) { + printf("%d\n", num); + fflush(stdout); +} + +int scan() { + char buffer[100]; + int res; + if (fgets(buffer, sizeof(buffer), stdin) != NULL) { + if (sscanf(buffer, "%d", &res) == 1) { + return res; + } + } + return 0; // or handle error +} \ No newline at end of file