Platform : x64 bit intel arch
Processor : intel core i5 processor
OS : RHEL6 linux
Compiler name : NASM
Assembly compiler src :
http://www.nasm.us/pub/nasm/releasebuilds/2.09.03/nasm-2.09.03.tar.gz
command : nasm
====
Programme :
vi hello.asm
-----
section .data ;section declaration
msg db "Hello, world!",0xa ;our dear string
len equ $ - msg ;length of our dear string
section .text ;section declaration
;we must export the entry point to the ELF linker or
global _start ;loader. They conventionally recognize _start as their
;entry point. Use ld -e foo to override the default.
_start:
;write our string to stdout
mov edx,len ;third argument: message length
mov ecx,msg ;second argument: pointer to message to write
mov ebx,1 ;first argument: file handle (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
;and exit
mov ebx,0 ;first syscall argument: exit code
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
-----
and save it as hello.asm
====
Compiling :
-----
[root@kmaiti assembly_test]# nasm -f elf hello.asm
-----
Linking(making one executable file using object files) :
-----
$ ld -s -o hello hello.o
or
[root@kmaiti assembly_test]# ld -m elf_i386 -s -o hello hello.o
Execution :
[root@kmaiti assembly_test]# ./hello
Hello, world!
[root@kmaiti assembly_test]# pwd
/home/kmaiti/Downloads/assembly_test
[root@kmaiti assembly_test]# /home/kmaiti/Downloads/assembly_test/hello
Hello, world!
[root@kmaiti assembly_test]#
-----
PS: [root@kmaiti assembly_test]# ld -m elf_i386 -s -o hello hello.o // Here code has compatible on 32 bit machine. But to compile it on 64bit machine, I used emulator here for 32bit machine. It's "elf_i386". An emulator in computer sciences duplicates (provides an emulation of) the functions of one system using a different system, so that the second system behaves like (and appears to be) the first system.
Try :)
Wednesday, 12 January 2011
First assembly programme on 64bit linux machine??
Posted on 21:27 by Unknown
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment