Assembly Basic Syntax
sumber : https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm
https://en.wikipedia.org/wiki/X86_instruction_listings
An assembly program can be divided into three sections :
- The
data
section - The
bss
section - The
text
section
The data Section
The data
section is used for declaring initialized data or constants. This data does not change at runtime. You can declare various constant values, file names, or buffer size, etc., in this section.
section.data
The bss Section
The bss
section is used for declaring variables.
section.bss
The text section
The text
section is used for keeping the actual code. This section must begin with the declaration global _start, which tells the kernel where the program execution begins.
section.text
global _start
_start:
Syntax
[label] mnemonic [operands] [;comment]
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
nasm -f elf hello.asm
ld -m elf_i386 -s -o hello hello.o
./hello
section .data
: tempat nyimpan data
text db "Hello world", 10
:
- nama memory address 'text'
- defining bytes 'db'
- berisi "Hello world" dan '10' / newline