Problem creating .exe file in x86

I am learning x86 assembly from Paul Carter's e-book.
I tried creating the first example program.
I used following switch to complie the first.asm as told in the book.

nasm -f coff first.asm

And created the exe file by linking the object files by gcc.exe of CodeBlocks (MinGW).
But it displays some symbols like 'G!!@' in the console.
Please help me.
Paul Carter's web page is currently down for me, and I don't have the PDF at hand.

My hunch is that you have linker errors?
Also I'm pretty sure you should use ld.exe and not gcc.exe to link object files.
OK, seems it's back online so I have the PDF and examples.

What exactly did you try to do? I'll try to help by doing the same thing.
First I created the file first.asm from notepad.exe and created its object file using nasm as told in the book. But I think that maybe I need to use object file formats other than coff. There aren't any linker errors. I'll try linking the object files by ld.exe.
Last edited on
ld.exe didn't help. Same output 'G!!@'.
I built an executable first.exe which crashes when run.
Here's how:

Using Nuwen's MinGW distro and NASM:
http://nuwen.net/mingw.html
http://www.nasm.us/pub/nasm/releasebuilds/2.10.09/win32/

Mind you I'm using an older version of Nuwen's MinGW, which is 32-bit, so you may have to specify -m32 when compiling, as in:
gcc -c -m32 driver.c


Then I downloaded Paul Carter's source code intended for Cygwin:
http://www.drpaulcarter.com/pcasm/cygwin-ex.zip

I copied the following files to a new folder:
asm_io.asm
asm_io.inc
cdecl.h
driver.c
first.asm


Then I ran:
gcc -c driver.c
nasm -f coff first.asm
nasm -f coff asm_io.asm
gcc -o first.exe driver.o first.o asm_io.o


As I said, the resulting executable crashes and never gets to print anything.
So maybe I messed up something as well.
Last edited on
I did the same; download example files for cygwin coz the book says it might work for MinGW as well. Can I use TC++ 3.0 compiler to link and complie the files since it's Borland software ?
I don't think that's a good idea, for the simple reason that TC++ 3.0 is too old.

If you absolutely want to try a free legacy Borland compiler, download the free version 5.5.
You will need to fill out a download form, then receive the download link in an e-mail.

http://www.embarcadero.com/products/cbuilder/free-compiler

I tried the "Microsoft" example source code with MinGW and NASM, and while it compiles to an executable, that executable still crashes.
nasm -f coff first.asm

Try changing coff to win32. Using Nuwen's MinGW with the Cygwin examples, it worked for me. Here's what I get:

--using coff
nasm -f coff first.asm
gcc -o first first.o driver.c asm_io.o
first
▀‼@

--using win32
nasm -f win32 first.asm
gcc -o first first.obj driver.c asm_io.o
first
Enter a number: 3
Enter another number: 2
You entered 3 and 2, the sum of these is 5
Sorry for the delay. win32 worked.
But how is it that the compiler could link asm_io.o but not first.o
I tried creating my own assembly program that will print a string on the screen. But the program crashes as Catfish4 said.
Just to add: currently the program first.exe doesn't crash for me, but its output is nasty.
Notice that it still prints the sum at the end.

Enter a number: 3
Enter another number: 5
Register Dump # 1
EAX = 00000008 EBX = 00000008 ECX = 00401DD0 EDX = 0008E3C8
ESI = 00000000 EDI = 00000000 EBP = 0028FF08 ESP = 0028FEE8
EIP = 00401727 FLAGS = 0202
Memory Dump # 2 Address = 004031B4
004031B0 72 3A 20 00 59 6F 75 20 65 6E 74 65 72 65 64 20 "r: ?You entered "
004031C0 00 20 61 6E 64 20 00 2C 20 74 68 65 20 73 75 6D "? and ?, the sum"
You entered 3 and 5, the sum of these is 8


I tried creating my own assembly program that will print a string on the screen. But the program crashes as Catfish4 said.

Help us help you. You need to give us the program source code to look at. And the error message when it crashes (if there is one).
Here's the source code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
; my own x86 program 
 %include "E:\NASMexamples\asm_io.inc"
segment .data
mymsg1 db "Let's see if this works !", 0

segment .text
global _asm_main
_asm_main:
mov eax, mymsg1
call print_string
call print_nl
call print_string
popa
mov eax,0
leave
ret


The error is 'The program myown.exe has stopped working correctly'.

But I got where the code was wrong. It should have been like this at line 9
1
2
3
enter 0,0
pusha
mov eax, mymsg1
Last edited on
Topic archived. No new replies allowed.