Начало проекта wayland

This commit is contained in:
Пытков Роман
2025-09-24 02:05:38 +03:00
parent 17096efe0f
commit 1698b43da6
7 changed files with 122 additions and 0 deletions

View File

@@ -3,6 +3,9 @@
{
"path": "casm"
},
{
"path": "wayland"
},
{
"path": "docs"
},

37
wayland/.vscode/launch.json vendored Normal file
View File

@@ -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
},
]
}
]
}

10
wayland/CMakeLists.txt Normal file
View File

@@ -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)

25
wayland/CMakePresets.json Normal file
View File

@@ -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"
}
}
]
}

23
wayland/asm.asm Normal file
View File

@@ -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

24
wayland/c.c Normal file
View File

@@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
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
}