rusi/include/stdvv.c

53 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// stdvv.c - реализация русского ввода/вывода
#include "stdvv.h"
long syscall3(long number, long arg1, long arg2, long arg3) {
asm("mov %rcx, %r10");
asm("mov %rdi, %rax");
asm("mov %rsi, %rdi");
asm("mov %rdx, %rsi");
asm("mov %r10, %rdx");
asm("syscall");
}
long длина_строки(const char *s) {
long len = 0;
while (s[len]) len++;
return len;
}
int печатьф(const char *формат, ...) {
long len = длина_строки(формат);
return (int)syscall3(1, 1, (long)формат, len);
}
int печать(const char *строка) {
long len = длина_строки(строка);
return (int)syscall3(1, 1, (long)строка, len);
}
int вывод_строки(const char *строка) {
int result = печать(строка);
симв_вывод('\n');
return result;
}
int симв_вывод(int c) {
char ch = (char)c;
return (int)syscall3(1, 1, (long)&ch, 1);
}
void завершение(int код) {
syscall3(60, код, 0, 0);
for (;;) {}
}
// assert - проверка условия для тестов
void assert(int expected, int actual, char *code) {
if (expected != actual) {
printf("ОШИБКА: ожидалось %d, получено %d (%s)\n", expected, actual, code);
завершение(1);
}
}