这个问题的灵感来自另一个论坛上某人提出的问题。在以下代码中,扩展内联程序集约束Rah和Ral含义是什么。我以前没见过这些:
#include<stdint.h>
void tty_write_char(uint8_t inchar, uint8_t page_num, uint8_t fg_color)
{
asm (
"int $0x10"
:
: "b" ((uint16_t)page_num<<8 | fg_color),
"Rah"((uint8_t)0x0e), "Ral"(inchar));
}
void tty_write_string(const char *string, uint8_t page_num, uint8_t fg_color)
{
while (*string)
tty_write_char(*string++, page_num, fg_color);
}
/* Use the BIOS to print the first command line argument to the console */
int main(int argc, char *argv[])
{
if (argc > 1)
tty_write_string(argv[1], 0, 0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
特别是在这段代码中使用Rah和Ral作为约束:
asm ( …Run Code Online (Sandbox Code Playgroud)