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:
hello.asm hello.o
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
global [space] _start rather than global_start will help with compilation.
ideal
model small
stack 256
dataseg
exCode db 0
message3 db “Hello world! 3333333333”,10,13,’$’
array dw 1, 2, 3, 4
no_message_var dw 7777h
codeseg
Start:
mov ax,@data
mov ds, ax
mov es, ax
;message length
mov edx,len
mov dx, offset message3
mov ah,9
int 21h
mov ah,01h
int 21h
mov ah,4ch
mov al,[exCode]
int 21h
end Start
my bols ich