[BITS 32]
section .data:
msg: db `Hello, World!\n\0` ; use backticks for the string
; note that we need to manually add the \0
section .text:
extern printf ; have to declare what functions we use
global main ; main is a global symbol (accessible from other files)
main:
push ebp ; standard prologue
mov ebp, esp ;
push msg ; push msg onto the stack (to use as an arg)
call printf ; printf(msg)
add esp, 4 ; clean up the arg we pushed
mov eax, 0 ; put return code in eax
mov esp, ebp ; standard epilogue
pop ebp ;
ret ;
[BITS 32]
[BITS 16]
, [BITS 64]
section .data:
msg: db `Hello, World!\n\0`
msg:
part defines a label. Labels are like pointers to memory inside
our program.db
directive tells the assembler to place actual values into the
program's memory. It stands for Define Byte.dw
(Define Word, 16 bit values) and dd
(Define Doubleword, 32 bits).char* msg = "Hello, World!\n";
section .text:
extern printf
global main
main:
push ebp
mov ebp, esp
push msg
call printf
printf(msg);
add esp, 4
mov eax, 0
mov esp, ebp
pop ebp
ret