This article walks you through the process of building a very simple program in assembly language in 5 minutes. Tutorial programs usually go by the name “Hello World” because that’s all they print out to the screen. Plenty of this information came from: http://www.tutorialspoint.com/assembly_programming/assembly_environment_setup.htm.
Install the tools.
yum install nasm -y
Create a file called “~/hello.asm” and populate it with the following:
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
Run the following from the same location as the “hello.asm” file.
nasm -f elf hello.asm
You will now have an additional file:
Now run the following:
ld -m elf_i386 -s -o hello hello.o
How you have an additional file called “hello”. You can execute the “hello” program as you would with any other program.
hello hello.asm hello.o