LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-19-2003, 05:54 AM   #1
usr
Member
 
Registered: Oct 2003
Posts: 44

Rep: Reputation: 15
another problem in assembly


I am trying to write a program in assembly(nasm) but I just don't know how to write a procedure. I tried with this code but it just doesn't work:

section .data
section .text
global _testroc
proc _test
mov ax,1
endproc
global _start
_start:
mov ebx,0
mov eax,1
int 0x80

Could someone tell me what is wrong and how can I fix this?

Thanks!
 
Old 01-31-2004, 01:54 AM   #2
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 417

Rep: Reputation: 31
This post is kinda old, so i bet you already figured it out...but if not, I suggest you read chapter 4 of dr carter's pdf "pc assembly" available at http://www.drpaulcarter.com/pcasm/
There is a program that uses procedures to print out "Hello" using kernel services (int 0x80).

Code:
section .data
msg     db      "Hello",0xA
len     equ     $-msg           ;length of msg

section .text
    global _start                       ;must be declared for linker (ld)


_start:                 ;we tell linker where is entry point

        call    print_string    ;print string
        call    terminate       ;then terminate!

print_string:
        mov     edx,len
        mov     ecx,msg
        mov     ebx,1   ;file descriptor (stdout)
        mov     eax,4   ;system call number (sys_write)
        int     0x80    ;call kernel
ret

terminate:
        mov     eax,1   ;system call number (sys_exit)
        int     0x80    ;call kernel

 ;NOTE THAT SINCE WE ARE PROGRAMMING IN PURE ASSEMBLY, AND
 ;NOT INTERFACING WITH LIBC, WE MUST USE SYS_EXIT TO TERMINATE
 ;OUR PROCESS OURSELVES.
compile like this:

nasm test.asm -f elf
ld test.o -o test
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem linking assembly program with C lib. 95se Programming 1 03-08-2005 09:44 PM
Assembly jinksys Programming 3 09-14-2003 04:33 PM
I need help for Assembly skb Programming 10 08-01-2003 04:51 PM
assembly genghis Programming 2 06-12-2003 07:46 AM
assembly sanjay pradhan Programming 1 02-01-2002 10:05 AM


All times are GMT -5. The time now is 07:32 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration