Reputation: 537
I'm quite new to assembly programming. I use NASM 2.11.05 on a Windows 7 (64-bit) platform to run some sample code. The problem arises when I try to call standard C functions from my assembly code. This is my assembly source:
global main
extern puts
section .text
main:
push message
call puts
ret
message:
db "Hola, mundo", 0
When I compile with NASM, I use this command line: nasm -fwin32 file.asm which produces file.obj. Now, when I try to link it with ld or gcc, I keep getting errors. Some things I tried:
gcc -m32 -nostartfiles file.obj (gives the error that i386:x86-64 architecture of input file is not compatible with i386 output).
ld file.obj (gives the error undefined reference to puts).
Can anyone please guide me on how to resolve this?
Upvotes: 1
Views: 490
Reputation:
You can just compile in a different way, like:
.asm
file with:
nasm -f elf file.asm
ld -m elf_i386 file.o -o file
gcc -m32 -o file file.o
./file
Upvotes: 0
Reputation: 537
In the end, one line at the top of my ASM file settled it. This is that line.
[BITS 32]
However, the output file still keeps crashing: anyone who can explain that is welcome!
Upvotes: 1