vak: (Default)
[personal profile] vak
Компилятор Би для БЭСМ-6 маленько подрос и уже способен правильно сгенерить функцию printf(). Вот как она выглядела в районе 1969 года.
printf(fmt, args) {
auto ap, a, c, i, n;

i = 0;
ap = &args;
loop:
while ((c = char(fmt, i)) != '%') {
if (c == '*0')
return;
writeb(c);
i = i + 1;
}
i = i + 1;
c = char(fmt, i);
if (c == '%') {
writeb('%');
i = i + 1;
goto loop;
}
a = *ap;
if (c == 'd') {
printd(a);
} else if (c == 'o') {
printo(a);
} else if (c == 'c') {
write(a);
} else if (c == 's') {
n = 0;
while ((c = char(a, n)) != '*0') {
writeb(c);
n = n + 1;
}
} else {
/* bad format specification, ignore */
goto loop;
}
i = i + 1;
ap = ap + 1;
goto loop;
}
Напишем тест, задействуя все форматы.
main() {
printf("Hello, World!*n");
printf("%% %% %%%%*n");
printf("format %%d: %d %d*n", 123, -123);
printf("format %%o: %o %o*n", 234, -234);
printf("format %%c: %c %c*n", 'foo', 'bar');
printf("format %%s: *"%s*" *"%s*"*n", "Hello", "World");
}
Компилируем, запускаем.
$ bbesm < test.b > test.assem 
$ besmc test.assem libb.obj
$ ./test.exe
Hello, World!
% % %%
format %d: 123 -123
format %o: 352 -352
format %c: foo bar
format %s: "Hello" "World"
Фунциклирует в лучшем виде однако.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org