the file and the commands in the same location

to see our architecture

uname -m

We will get:

x86_64

The executable is only to be run on computers of the same architecture.

If you want to generate an executable for x86_64 from a system that uses the i386 architecture, you must perform a cross-compile.

The i386 architecture is 32-bit, while x86_64 is 64-bit. Although both architectures are compatible in terms of instructions, the size of the words and addresses is different.

.asm is the source code file for assembly language.

When an .asm file is compiled, an object file (usually with the extension .o) is generated that contains the machine code generated from the assembly code.

However, this object file is not directly executable.

To generate an executable, you need to link the object file with the libraries and other object files needed to create a complete executable.

The end result is an executable file (usually without extension in Linux) that can be run directly on the machine.

  • .asm: assembly code file
  • .o: object file generated after compilation
  • no extension: executable file generated after linking

asm code:

hola_mundo.asm

default rel

section .data
    msg db 'Hola Mundo!', 0

section .text align=16
    global _main
    extern _puts

_main:
    ; imprimir la cadena en la salida estándar
    lea rdi, [rel msg]     ; dirección de la cadena
    call _puts

    ; salir del programa
    mov rax, 0x2000001   ; sys_exit
    xor rdi, rdi          ; código de salida (0)
    syscall

using an IDE like visual studio code to write:

then execute:

 nasm -f macho64 hola_mundo.asm -o hola_mundo.o
clang -o hola_mundo hola_mundo.o
./hola_mundo

you will be able to see:

Hola Mundo!

Your folder should look like this, after running the commands the .o and the executable are generated

If you click on the executable you will see this: