简体   繁体   English

c引导加载程序传递函数参数不起作用

[英]c bootloader passing function parameters doesn't work right

I have a basic bootloader in c, but when I try to pass a parameter to a function, it doesn't work quite right. 我在c中有一个基本的引导加载程序,但是当我尝试将参数传递给函数时,它不能正常工作。 The following code doesn't work: 以下代码不起作用:

__asm__(".code16\n");
__asm__("call main\n");

void main(){
    putchar('X');
    while(1){}
}

void putchar(char c){
    __asm__("movb %0, %%al\n" : : "r"(c));
    __asm__("movb $0x0e, %ah\n");
    __asm__("int $0x10\n");
}

It should print out an X, but instead it just moves the cursor forward as if printing a space. 它应该打印出一个X,但是相反,它只是将光标向前移动,就像打印一个空格一样。

The following code works because it doesn't pass the character as a parameter: 以下代码有效,因为它没有将字符作为参数传递:

__asm__(".code16\n");
__asm__("call main\n");

char c;

void main(){
    c = 'X';
    putchar();
    while(1){}
}

void putchar(){
    __asm__("movb %0, %%al\n" : : "r"(c));
    __asm__("movb $0x0e, %ah\n");
    __asm__("int $0x10\n");
}

Can someone explain why it isn't working? 有人可以解释为什么它不起作用吗?

The problem wasn't the fact that it was being passed as a parameter, but rather, I was using the assembly wrongly. 问题不是它作为参数传递的事实,而是我错误地使用了程序集。 The following code works: 以下代码有效:

__asm__(".code16\n");
__asm__("call main\n");

void main(){
    putchar('!');
    while(1){}
}

void putchar(char c){
    __asm__ __volatile__("int $0x10" : : "a"(0x0e00 | c), "b"(0x0007));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM