获取总​​线错误在大会在线编程86 [英] Getting a bus error in Assembly in-line programming x86

查看:184
本文介绍了获取总​​线错误在大会在线编程86的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了一个汇编语言编程的挑战,我需要找到原因如下code试图运行它时,给出了一个总线错误。很多谷歌搜索后,我仍然无法弄清楚,为什么..我的集会86不是很​​大的了解,在寻找解决任何提示将是非常美联社preciated。

下面是code:

 的#include<&stdlib.h中GT;
诠释主要(无效){
  ASM(PUSHF \\ n
      ORL $ 0x40000(%ESP)\\ n
      POPF \\ n);  *(为(int *)(((字符*)malloc的(5))+ 1))= 23; //此行会导致总线错误
  返回0;
}


解决方案

从本质上讲要设置在标志一个标志寄存器。标志0x40000,又名位18而根据 http://en.wikipedia.org/wiki/ FLAGS_register_%28computing%29

18 AC对齐检查(486SX +专用)X

如果你搜索标志对齐检查你发现除其他:

http://forum.soft32.com/linux2/打开86校准 - 检查 - ftopict12003.html

我希望这台你在正确的轨道上。但你真的有一个486SX?

I stumbled upon an assembly programming challenge where I need to find why the following code gives a Bus Error when trying to run it. After much googling, I still can't figure out why.. My understanding of assembly x86 not great, any tips on finding the solution would be very appreciated.

Here is the code:

#include <stdlib.h>
int main(void) {
  asm("pushf\n"
      "orl $ 0x40000, (%esp)\n"
      "popf\n");

  *((int*) (((char*) malloc(5)) + 1)) = 23; // This line causes the Bus Error


  return 0;
}

解决方案

Essentially you are setting a flag in the flags register. Flag 0x40000, aka bit 18 which according to http://en.wikipedia.org/wiki/FLAGS_register_%28computing%29 is

18 AC Alignment check (486SX+ only) X

If you search for "flag alignment check" you find amongst others:

http://forum.soft32.com/linux2/Turn-x86-Alignment-Check-ftopict12003.html

I hope this sets you on the right track. But do you really have a 486SX?

这篇关于获取总​​线错误在大会在线编程86的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆