Here we document all the things that deviate or extend the original description of the B programming language from kbman.
main() {
printf("Hello, World\n");
}
extrn printf;printf is now visible to all the functions in the global scope.
main() {
// for gas-x86_64-linux
__asm__(
"movq $60, %rax", // exit syscall number
"movq $69, %rdi", // exit code
"syscall"
);
}__asm__ is a function-like statement that takes a list of string literals as arguments and passes them directly to the assembler.
// for gas-x86_64-linux
main __asm__(
"movq $69, %rax",
"ret"
);These are a special kind of function for which the compiler does not generate a prologue or an epilogue.
the syntax is name __asm__(...); (this is different from name() __asm__(...);).
extrn printf;
__variadic__(printf, 1);
main() {
printf("Hello, world!\n");
}Some targets like gas-aarch64-darwin have a different calling convention for variadic functions from normal ones,
this is needed to make the compiler use the correct calling convention.
the syntax is __variadic__(function_name, number_of_fixed_args);