; Macros used in NASM assembler
%define SYS_EXIT 1
%define SYS_READ 3
%define SYS_WRITE 4
%define STDOUT 1
%define STATUS 0
%define SYS_INTR 0x80
section .data
hello: db 'Hello World!', 10 ;NOTE This 10 is for new line
;hello: db 'Hello World!'
helloLen: equ $-hello ;This will have the length of helloLen
; Note unlike "hello", helloLen is not an address; but value
section .text
global _start
_start:
;Printing Hello World String.
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, hello
mov edx, helloLen
int SYS_INTR
;Exit from main program
mov eax, 1
mov ebx, 0
int SYS_INTR
ret ; This will not get executed at all
%define SYS_EXIT 1
%define SYS_READ 3
%define SYS_WRITE 4
%define STDOUT 1
%define STATUS 0
%define SYS_INTR 0x80
section .data
hello: db 'Hello World!', 10 ;NOTE This 10 is for new line
;hello: db 'Hello World!'
helloLen: equ $-hello ;This will have the length of helloLen
; Note unlike "hello", helloLen is not an address; but value
section .text
global _start
_start:
;Printing Hello World String.
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, hello
mov edx, helloLen
int SYS_INTR
;Exit from main program
mov eax, 1
mov ebx, 0
int SYS_INTR
ret ; This will not get executed at all
Command to Assemble:
nasm -f elf hello.asm
Command to Link:
ld -s -o hello hello.o -m elf_i386 (Note elf_i386 denotes that this needs to be linked for 32 bit application)
No comments:
Post a Comment