Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;This is a hello world program, but seems to be really hard, and now I'm compiling in Linux x86
- ;and this is not by me, you can found it here
- ;http://en.wikipedia.org/wiki/X86_assembly_language#.22Hello_world.21.22_program_for_Linux_in_NASM_style_assembly
- ;I will keep shearching I try to make modifications and try to print just values and caracters
- ;Sorry about mistakes in last shared snippet
- ;In linux we need the "_start:" otherwise we will get an error
- ;So, keep up and sorry again
- ;
- ; This program runs in 32-bit protected mode.
- ; build: nasm -f elf -F stabs name.asm
- ; link: ld -o name name.o
- ;
- ; In 64-bit long mode you can use 64-bit registers (e.g. rax instead of eax, rbx instead of ebx, etc.)
- ; Also change "-f elf " for "-f elf64" in build command.
- ;
- section .data ; section for initialized data
- str: db 'Hello world!', 0Ah ; message string with new-line char at the end (10 decimal)
- str_len: equ $ - str ; calcs length of string (bytes) by subtracting the str's start address
- ; from this address ($ symbol)
- section .text ; this is the code section
- global _start ; _start is the entry point and needs global scope to be 'seen' by the
- ; linker --equivalent to main() in C/C++
- _start: ; definition of _start procedure begins here
- mov eax, 4 ; specify the sys_write function code (from OS vector table)
- mov ebx, 1 ; specify file descriptor stdout --in gnu/linux, everything's treated as a file,
- ; even hardware devices
- mov ecx, str ; move start _address_ of string message to ecx register
- mov edx, str_len ; move length of message (in bytes)
- int 80h ; interrupt kernel to perform the system call we just set up -
- ; in gnu/linux services are requested through the kernel
- mov eax, 1 ; specify sys_exit function code (from OS vector table)
- mov ebx, 0 ; specify return code for OS (zero tells OS everything went fine)
- int 80h ; interrupt kernel to perform system call (to exit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement