Сложение двух чисел в консоли

This commit is contained in:
Пытков Роман
2025-09-20 20:32:39 +03:00
parent 98877d6100
commit d7cb83d869
3 changed files with 19 additions and 3 deletions

View File

@@ -5,7 +5,6 @@
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
// Resolved by CMake Tools:
"program": "${command:cmake.launchTargetPath}",
"args": [],
"cwd": "${workspaceFolder}",

View File

@@ -1,7 +1,18 @@
global main
extern sum, print, scan
section .text
main:
mov rdi, 125
push rbx ; сохранить rbx
call scan ; прочитать первое число
mov rbx, rax ; сохранить первое число
call scan ; прочитать второе число
mov rdi, rbx ; a
mov rsi, rax ; b
call sum ; сумма
mov rdi, rax ; результат
call print ; напечатать
pop rbx ; восстановить rbx
mov rdi, 0
mov rax, 60
syscall

View File

@@ -5,5 +5,11 @@ int sum(int a, int b) {
}
void print(int num) {
printf("%d", num);
printf("%d\n", num);
}
int scan() {
int res;
scanf("%d", &res);
return res;
}