首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

Visual C++6.0嵌入汇编代码里调用BIOS INT 10H中断的异常

2012-10-20 
Visual C++6.0嵌入汇编代码里调用BIOS INT 10H中断的错误大致是,我用Visual C++6.0写了个简单的输出Hello

Visual C++6.0嵌入汇编代码里调用BIOS INT 10H中断的错误
大致是,我用Visual C++6.0写了个简单的输出Hello World!程序,然后想嵌入汇编代码,在屏幕上显示HELLO WORLD红色的字(调用INT中断),网上搜到段代码是:

C/C++ code
    _asm    {        mov ax,0600h        mov bh,0c1h            mov cx,0000h        mov dx,184fh        int 10h    }

可是运行到int 10h时,总有个错误框,框框上内容是:Unhandled exception in hello.exe:0xC0000005:Access Violation.
也就是在调用BIOS INT 10H中断时总出错,请问这是怎么回事?要怎么解决?

[解决办法]

http://www.masmforum.com/board/index.php?PHPSESSID=8d46cd4ecb1688be429ab49694ec53e6&topic=5281.0;wap2
In 32 bit Windows you cannot use the INT10H functions at all and for a console based 32 bit app, you use the normal console API function calls. They do the normal IO with no problems but note that in comparison to 16 bit DOS console apps, they are slower at screen upgrades and the like.

http://stackoverflow.com/questions/9121136/intel-x86-32-bit-interrupt
1. If you run you program in real mode (under MS-DOS, for example), you'll be able to use the same DOS/BIOS services you used to in your 16-bit programs.
2. I'm afraid you won't be able to specify that you are going to use 32-bit registers as there are no 32-bit support for BIOS int 10h, int 13h, etc. Only the contents of 16-bit registers will be taken into account.


[解决办法]
应该以前学通信的,多多少少了解些,但是不一定100%正确。简单的说下,仅供参考。

int 10h,int 21h 这些在VC下是不能被调用的,因为他们不能在保护模式下调用,只能在实模式下调用。

如果想用汇编写个hello world,也比较简单。

可以这么写:
C/C++ code
#include <stdio.h>#include <stdlib.h>int main(int argc, char* argv[]){     char *s="hello,world\n";    _asm    {            push s        call printf        add esp,4            }    return 0;} 

热点排行