LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   another problem in assembly (https://www.linuxquestions.org/questions/programming-9/another-problem-in-assembly-127201/)

usr 12-19-2003 05:54 AM

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 _test:proc
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!

jinksys 01-31-2004 01:54 AM

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


All times are GMT -5. The time now is 12:37 PM.