mik*_*ike 2 c linux x86 gcc inline-assembly
我在一个小程序中包含了一些示例ASM代码来进行测试.
我的计划是:
#include <stdio.h>
static inline
unsigned char inb (int port) {
unsigned char data;
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
return data;
}
int main()
{
printf("hello world %d\n", inb(22));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,它在执行ASM代码时因分段错误而崩溃.有人能告诉我这个小程序有什么问题吗?非常感谢.
您需要ioperm在允许使用端口I/O之前使用.另外,请注意内核已经提供inb和outb功能.
使用ioperm(2)或iopl(2)告诉内核允许用户空间应用程序访问相关的I/O端口.如果不这样做,将导致应用程序收到分段错误.
| 归档时间: |
|
| 查看次数: |
528 次 |
| 最近记录: |