how to assemble and link:
nasm -f elf32 -o <filename>.o <filename>.asm
ld -m elf_i386 -o <filename> <filename>.otemplate code (hello world):
section .text
global _start
_start:
mov ebx, 0x1
mov ecx, hello
mov edx, helloLen
mov eax, 0x4
int 0x80
xor ebx, ebx
mov eax, 0x1
int 0x80
section .data
hello db "Hello World", 0xa
helloLen equ $-hellohow to assemble and link:
nasm -f elf64 -o <filename>.o <filename>.asm
ld -o <filename> <filename>.otemplate code (hello world):
section .text
global _start
_start:
mov rdi, 0x1
mov rsi, hello
mov rdx, helloLen
mov rax, 0x1
syscall
xor rdi, rdi
mov rax, 0x3c
syscall
section .data
hello db "Hello World", 0xa
helloLen equ $-hellohow to assemble and link:
nasm -f elf32 -o <filename>.o <filename>.asm
ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o <filename> -lc <filename>.otemplate code (hello world):
extern puts
extern exit
section .text
global _start
_start:
push hello
call puts
add esp, 0x4
mov eax, 0xa
call exit
section .data
hello db "Hello World"how to assemble and link:
nasm -f elf64 -o <filename>.o <filename>.asm
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o <filename> -lc <filename>.otemplate code (hello world):
extern puts
extern exit
section .text
global _start
_start:
mov rdi, hello
call puts
add rsp, 0x8
mov rax, 0xa
call exit
section .data
hello db "Hello World"__NOTE__:
- Assembler Directives: instructions for the assembler (e.g. NASM) and not a part of the ISA
- extern: declare a symbol which is defined in another module that will later be linked with current one
- section: identifies the section the code you write will go into. Examples of common ones are .text, .data, and .bss
- global: defines symbols such that other modules that EXTERN those symbols can correctly reference them after linking
Thank you, your template code helps me a lot