LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 857|回复: 8

请问一下,下面这段程序如何改正?

[复制链接]
发表于 2006-5-11 17:59:15 | 显示全部楼层 |阅读模式
set_cursor.c
[PHP]int main()
{
  __asm__(
          "movb $5,%ch
           movb $7,%cl
           movb $1,%ah
           int $0x10
           movb $4,%dh
           movb $5,%dl
           movb $0,%bh
           movb $2,%ah
           int $0x10"
          );
  return 0;
}
[/PHP]
当我用gcc -o set_cursor set_cursor.c时,它的输出信息是这样的:
[PHP]set_cursor.c: In function `main':
set_cursor.c:4: error: missing terminating " character
set_cursor.c:5: error: `movb' undeclared (first use in this function)
set_cursor.c:5: error: (Each undeclared identifier is reported only once
set_cursor.c:5: error: for each function it appears in.)
set_cursor.c:5: error: syntax error before "$7"
set_cursor.c:12: error: missing terminating " character
[/PHP]
发表于 2006-5-11 18:22:52 | 显示全部楼层
提供两种方法, 应该都可以
[PHP]
int main()
{
  __asm__(
      "movb $5,%ch"
      "movb $7,%cl"
      "movb $1,%ah"
      "int $0x10"
      "movb $4,%dh"
      "movb $5,%dl"
      "movb $0,%bh"
      "movb $2,%ah"
      "int $0x10"
      );
  return 0;
}
[/PHP]
[PHP]
int main()
{
  __asm__(
      "movb $5,%ch \
       movb $7,%cl \
       movb $1,%ah \
       int $0x10   \
       movb $4,%dh \
       movb $5,%dl \
       movb $0,%bh \
       movb $2,%ah \
       int $0x10"
      );
  return 0;
}
[/PHP]
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-11 21:01:15 | 显示全部楼层
用第一种方法,有以下错误:
[PHP]/tmp/ccyakTVl.s: Assembler messages:
/tmp/ccyakTVl.s:17: Error: bad register name `%chmovb $7'
[/PHP]
回复 支持 反对

使用道具 举报

发表于 2006-5-11 21:38:47 | 显示全部楼层
这涉及到c语言跨行字符串常量的格式问题

第一种两行之间没有空白,结果%ch就和下面的movb贴在一起了,每行最后引号前加个空格试试
第二种在最后有空格,所以没出错
我想应该是这个原因吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-11 23:08:04 | 显示全部楼层
加了就有这样的错误信息,和第二种方法一样:
[PHP]/tmp/ccqD5dsh.s: Assembler messages:
/tmp/ccqD5dsh.s:17: Error: junk `movb $7' after register
[/PHP]
回复 支持 反对

使用道具 举报

发表于 2006-5-12 12:50:38 | 显示全部楼层
加 分号呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-12 12:57:11 | 显示全部楼层
在每一行后面加分号?
回复 支持 反对

使用道具 举报

发表于 2006-5-12 13:38:43 | 显示全部楼层
  1. int main()
  2. {
  3.   __asm__(
  4.       "movb $5,%ch;"
  5.       "movb $7,%cl;"
  6.       "movb $1,%ah;"
  7.       "int $0x10;"
  8.       "movb $4,%dh;"
  9.       "movb $5,%dl;"
  10.       "movb $0,%bh;"
  11.       "movb $2,%ah;"
  12.       "int $0x10;"
  13.       );
  14.   return 0;
  15. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-12 20:13:41 | 显示全部楼层
行了,只是由于是保护模式,所以运行是有段错误.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表