当GNU汇编在Cygwin中运行hello.s分段故障 [英] Segmentation fault when run hello.s by GNU Assembler in Cygwin

查看:204
本文介绍了当GNU汇编在Cygwin中运行hello.s分段故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gcc Cygwin中(在Windows7-64位)来运行这个例子
http://asm.sourceforge.net/howto/build.html

I use gcc in Cygwin (in Windows7-64 bit) to run this example http://asm.sourceforge.net/howto/build.html

.data                   # section declaration
msg:
    .ascii  "Hello, world!\n"   # our dear string
    len = .-msg         # length of our dear string
.text                   # section declaration
            # we must export the entry point to the ELF linker or
    .global _start  # loader. They conventionally recognize _start as their
            # entry point. Use ld -e foo to override the default.
_start:
# write our string to stdout
    movl    $len,%edx   # third argument: message length
    movl    $msg,%ecx   # second argument: pointer to message to write
    movl    $1,%ebx     # first argument: file handle (stdout)
    movl    $4,%eax     # system call number (sys_write)
    int $0x80       # call kernel
# and exit
    movl    $0,%ebx     # first argument: exit code
    movl    $1,%eax     # system call number (sys_exit)
    int $0x80       # call kernel

在Cygwin的命令行
     $为-o hello.o hello.s&放大器;&安培; LD -s -o你好hello.o和放大器;&安培; ./hello
其结果是
    分段故障

你能帮助我吗?

推荐答案

Cygwin的好好尝试一下让使用Linux的Windows二进制兼容,因此Linux系统调用INT使用0x80的$与Windows对系统调用一个完全不同的约定将失败。生成的二进制文件应该可以正常工作在实际(或兼容)Linux环境下,虽然。

Cygwin doens't make Windows binary-compatible with Linux, so Linux system calls using int $0x80 will fail as Windows has a completely different convention for system calls. The generated binaries should work fine in an actual (or compatible) Linux environment, though.

这篇关于当GNU汇编在Cygwin中运行hello.s分段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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