притянут C++

This commit is contained in:
Пытков Роман
2025-09-20 22:12:40 +03:00
parent 241f5acf71
commit a6d997f61d
4 changed files with 19 additions and 2 deletions

View File

@@ -7,4 +7,4 @@ enable_language(ASM_NASM)
set(CMAKE_ASM_NASM_FLAGS "-f elf64")
set(CMAKE_ASM_NASM_FLAGS_DEBUG "-gdwarf")
add_executable(casm asm.asm c.c)
add_executable(casm asm.asm c.c cpp.cpp)

View File

@@ -1,5 +1,5 @@
global main
extern sum, print, scan
extern sum, print, scan, test_vector, a
section .text
main:
@@ -12,7 +12,11 @@ main:
call sum ; сумма
mov rdi, rax ; результат
call print ; напечатать
call test_vector
pop rbx ; восстановить rbx
mov dword [rel a], 42 ; записать значение 42 в переменную a
mov rdi, 0
mov rax, 60
syscall

View File

@@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
int a;
int sum(int a, int b) {
return a+b;
}

11
casm/cpp.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include <vector>
#include <iostream>
extern "C" void test_vector() {
std::vector<int> vec = std::vector<int>();
for(auto i = 0; i < 10; i++)
vec.push_back(i);
for(auto num : vec)
std::cout << num << ", ";
std::cout << std::endl;
}