1
votes

I'm following those video tutorials on the assembly language. I'm basically trying to work out the "hello world" asm example. Here is what I've got:

.data
str:
        .ascii "Hello World"

.text
.globl _start

_start:
        movl    $4, %eax
        movl    $1, %ebx
        movl    $str, %ecx
        movl    $11, %edx
        int     $0x80

        movl    $1, %eax
        movl    $0, %ebx
        int     $0x80

This compiles just fine but when I run it, no text is printed to the terminal. I have no idea what I'm doing wrong. Whatever value I mov into the ecx register makes no difference, nothing happens.

Also, other question, how does the syscall work when it call the int 0x80 instruction ? Some data has been moved to the registers but when we get to the syscall, it doesn't "use" any of those values. Does it go and get what has been moved to those registers on it's own ?

Some system info that might be helpful:

dominic-@-freebsd-9 ~/dev/asm/tutorial > uname -a
FreeBSD freebsd-9 5.5-RELEASE FreeBSD 5.5-RELEASE #0: Tue May 23 14:58:27 UTC 2006     [email protected]:/usr/obj/usr/src/sys/GENERIC  i386
3
My personal opinion is that starting assembly by learning system calls, "hello world", calling conventions and other OS dependent features is a bad idea. I usually recommend learning the use of a debugger and writing little self-contained asm programs that you can single step, such as summing up a small array. Once you are happy with the basic instructions and get the hang of assembly, you can easily learn the various other things, whereby knowing system calls may not even be useful. But that's just my crazy view :)Jester

3 Answers

1
votes

I think you need Linux emulation for this to work. Take a look into Developer's Handbook for details.

1
votes

FreeBSD has the more 'usual' calling convention, where the syscall number is in eax, and the parameters are on the stack

check out the freebsd section of this hello world in assembly totorial

I go between ubuntu and netbsd and that helped me write assembly for both

*bsd uses a stack to store the arguments of the file des and the length of bytes to write, in linux it's just kept in the registers eax and ebx which is linux style, as you have in your example.

in linux: _start:;tell linker entry point mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel

in freebsd:

_syscall:
    int0x80;system call
    ret 

_start:;tell linker entry point

    pushd word len;message length
    pushd word msg;message to write
    pushd word 1;file descriptor (stdout)
    move ax,0x4;system call number (sys_write)
    call _syscall;call kernel

use the stack version for syscalls on *bsd

0
votes

You need to have %ebx set to 0 (stdout). Your current value (1) means stdin.