1
votes

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:

  1. gcc -m32 -nostartfiles file.obj (gives the error that i386:x86-64 architecture of input file is not compatible with i386 output).

  2. ld file.obj (gives the error undefined reference to puts).

Can anyone please guide me on how to resolve this?

2
On Linux based OS this works for me using your original code without the bits 32 . nasm -felf32 dedduwage_001.s -o dedduwage_001.o && gcc dedduwage_001.o -o dedduwage_001 -m32. - InfinitelyManic

2 Answers

1
votes

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!

0
votes

You can just compile in a different way, like:

  • Create an object of your .asm file with:
    1. GCC: nasm -f elf file.asm
      or
    2. LD: ld -m elf_i386 file.o -o file

  • Link object file created with gcc -m32 -o file file.o
  • Run with ./file