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