Kamil Witkowski
Kamil Witkowski

Reputation: 2083

exe file exits, nasm program working fine

I've got problem, I can compile these programs:

I named file p4.asm - c program:

#include <stdio.h>


extern float liczbae(int n);

int main()
{
    int n = 6;

        float wynik;
    int wait = 0;
    printf("Program liczy wartosc e z podana dokladnoscia");
        printf("\n\nPodaj dokladnosc: ");
    scanf("%d", &n);
        wynik = liczbae(n);
        printf("\ne = %f", wynik);
                scanf("%d", &wait);
    return 0;
}

I named file p2.c

now in nasm i can compile it with Borland with following lines:

cd C:\Users\jaa\Desktop\assembler projekt 2    
nasm p4.asm -f obj -o obj.obj
set path=C:\Borland\BCC55\Bin;%path%
bcc32 p2.c obj.obj
p2

but, when i compile using gcc, with following lines:

cd C:\Users\jaa\Desktop\assembler projekt 2
nasm -f coff p4.asm -o plik.o
set path=%pah%;C:\mingw\bin
gcc  p2.c -c -o plik1.o
gcc plik.o plik1.o -o plik.exe

plik.exe runs, but it crashes when i type 11 and enter but that error doesn't occur in nasm. I wonder why?

Upvotes: 1

Views: 235

Answers (1)

rkhb
rkhb

Reputation: 14409

As Frank pointed out, the format for NASM with MingW-GCC should be -f win32.

I'm surprised that it works with BCC32 (version here: 5.8.2). There is a variable in the .text section that is accessed for writing by fstp dword [n]. The .text section should not be writeable.

Insert the line

section .data use32 class=DATA

after ret and

change

section .text use32

to

section .text use32 class=CODE

Upvotes: 1

Related Questions