0

I am using Cygwin 32-bit under Win7 in a 64-bit machine.

The following program

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;
} 

is giving me the following error:

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)

I am not understanding why this error is being generated.

How can I get rid of this issue?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user366312
  • 16,949
  • 65
  • 235
  • 452

0 Answers0