First assembly programme on 64bit linux machine??



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.

By : singlehop.com



Related Posts:



Responses

0 Respones to "First assembly programme on 64bit linux machine??"

Post a Comment

»Thank you for reading this article
If you have questions or comments, please leave a comment
»You can click on the Subscribe by email to subscribe comments of this post
»You can register directly link pictures, mp3, video on the comment form.
»You may use some HTML tags such
»Please post comments polite and typing accented Vietnamese if possible
»Thank the good faith comment

 

Categories

Recent Comments

Error loading feed.

Total Pageviews

624888
Return to top of page ©Web Server Tips Tricks 2010 | Develop by Mr.PhanQuan .Powered by Blogger . All rights reserved.