Начало проекта wayland
This commit is contained in:
@@ -3,6 +3,9 @@
|
|||||||
{
|
{
|
||||||
"path": "casm"
|
"path": "casm"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "wayland"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "docs"
|
"path": "docs"
|
||||||
},
|
},
|
||||||
|
|||||||
37
wayland/.vscode/launch.json
vendored
Normal file
37
wayland/.vscode/launch.json
vendored
Normal 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
10
wayland/CMakeLists.txt
Normal 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
25
wayland/CMakePresets.json
Normal 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
23
wayland/asm.asm
Normal 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
24
wayland/c.c
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user