在Cygwin下使用Linux int 80h系统调用?

时间:2019-04-03 23:52:21

标签: c assembly makefile cygwin nasm

我在64位计算机上的Win7下使用 Cygwin 32位

以下程序

makefile

runme:  main.cpp    asm.o
    g++     main.cpp    asm.o   -o  executable

asm.o:  asm.asm
    nasm    -f   elf    asm.asm     -o  asm.o

asm.asm

    section .data
    hello:     db 'Hello world!',10
    helloLen:  equ $-hello
section .bss
section .text
    global _GetValueFromASM, _HelloWorld

_GetValueFromASM:
    mov eax, 9
    ret

_HelloWorld:
    mov eax,4            ; 'write' system call = 4
    mov ebx,1            ; file descriptor 1 = STDOUT
    mov ecx,hello        ; string to write
    mov edx,helloLen     ; length of string to write
    int 80h              ; call the kernel
    ret

main.cpp

#include <iostream>

using namespace std;

extern "C" int GetValueFromASM();
extern "C" int HelloWorld();

int main()
{
    HelloWorld();
    cout<<"GetValueFromASM() returned = "<<GetValueFromASM()<<endl;

    return 0;
} 

给我以下错误:

me@my-PC ~/nasm/test of Intel syntax
$ make
nasm    -f      elf             asm.asm         -o      asm.o
g++       main.cpp        asm.o   -o      executable

me@my-PC ~/nasm/test of Intel syntax
$ ./executable
Segmentation fault (core dumped)

我不明白为什么会产生此错误。

如何摆脱这个问题?

0 个答案:

没有答案
相关问题