[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Assembly Language Programs



On Wed, Apr 12, 2006 at 09:22:49AM +0200, Alessandro Coppelli wrote:
> Hi to all.
> I am interested to developing a little
> assembly language programs.
> 
> I rode the article written by Thomas Sommers
> ( http://user.nj.net/~tms/hello.html )
> I followed author's instructions but at the end of compilation
> 
>   as -o <name>.o <name>.s
>   ld -o <name> <name>.o
> 
> what I have is
> 
>  #./<name>
>  #ksh: Operation not permitted
> 
> 
>  Someone knows what is happenig ?
> 
> Ale
> 
>

Yes, your file is not recognized as valid OpenBSD ELF executable.

Try this:

-- 8< -- (hello.s)
section .text
    global _start

msg     db      "Hello, world!",0xa
len     equ     $ - msg

_syscall:
        int 0x80
        ret

_start:
        push    dword len
        push    dword msg
        push    dword 1         ; stdout 
        mov     eax,0x4         ; write
        call    _syscall

        add     esp,12

        push    dword 0
        mov     eax,0x1
        call    _syscall


Valid OpenBSD elf header :)
-- 8< -- (obsd-elf.s)
.section ".note.openbsd.ident", "a"
        .p2align 2
        .long   8
        .long   4
        .long   1
        .ascii "OpenBSD\0"
        .long   0
        .p2align 2

Compile and link it...

$ as obsd-elf.s -o obsd-elf.o
$ nasm -f elf -o hello.o hello.s
$ ld -s -o hello hello.o obsd-elf.o
$ ./hello
Hello, world!


Tobias