Very newbie question...
Hi,
i have some problems with my first linux/nasm asm program.
This is a simple "hello world" program but i can't see the "hello world" on my screen and i don't find my error. I work on 64bit amd system.
Someone can illuminate me? :)
Thx
-----------------------------------
section .text
global _start
msg db 'hello, world!',0xa
len equ $ - msg
_start:
push ebp
mov ebp,esp
push len push msg push 1 mov ebx,esp mov eax,4 int 0x80
add esp,12
mov ebx,0 mov eax,1 int 0x80
I am still newbie myself, but one thing that I noticed is that you pass some parameters via registers and others via the stack pointer.
The write sys call takes 3 param (as you prob already know), the file descriptor (1 = stdout), the pointer to the buffer, and its size.
The write sys call itself is syscall 4.
According to http://asm.sourceforge.net/articles/linasm.html
"For all syscalls, the syscall number goes in %eax. For syscalls that have less than six args, the args go in %ebx,%ecx,%edx,%esi,%edi in order. The return value of the syscall is stored in %eax."
Here is my own example that I wrote about a year ago.
section .data
hello db 'Hello, World!', 0Ah
len equ $-hello
section .text
global _start_start:
mov edx, len mov ecx, hello mov ebx, 1 mov eax, 4 int 80h mov ebx, 0 mov eax, 1 int 80h
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Lorenzo
Sent: Friday, November 11, 2005 6:05 PM
To: [email protected]
Subject: Very newbie question...
Hi,
i have some problems with my first linux/nasm asm program. This is a simple "hello world" program but i can't see the "hello world" on my screen and i don't find my error.
I work on 64bit amd system.
Someone can illuminate me? :)
Thx
-----------------------------------
section .text
global _start
msg db 'hello, world!',0xa
len equ $ - msg
_start:
push ebp
mov ebp,esp
push len
push msg
push 1
mov ebx,esp
mov eax,4
int 0x80
add esp,12
mov ebx,0
mov eax,1
int 0x80-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines
i have some problems with my first linux/nasm asm program. This is a simple "hello world" program but i can't see the "hello world" on my screen and i don't find my error.
As noted, you are confusing the function call method with the system call method, and doing a little of both. You need to decide on one or the other.
If you want to make direct kernel system calls, then follow the code that was posted earlier. Alternately, if you wanted to use the POSIX functions, your code would look something like this:
EXTERN write, _exit
; ...
push len push hello push 1 call write add esp, 12 push 0 call _exit
b
Ah ok... now i understand some more things :)
Thx :)
Quoted 29 lines · Brian Raiter
As noted, you are confusing the function call method with the system call method, and doing a little of both. You need to decide on one or the other.
If you want to make direct kernel system calls, then follow the code that was posted earlier. Alternately, if you wanted to use the POSIX functions, your code would look something like this:
EXTERN write,
_exit; ...
push len push hello push 1 call write add esp, 12 push 0 call _exitb
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I have tried to do a program like yours and all is ok. The "Hello World" work well but i don't want to use this method. In the same page,
http://asm.sourceforge.net/articles/linasm.html, there is another thing:
" Syscalls whos number of args is greater than five still expect the syscall number to be in %eax, but the args are arranged in memory and the pointer to the first arg is stored in %ebx."
I know that "Hello World" is composed of less then five args but i want to know both methods (put all in eax,ebx,ecx,edx,esi,edi registers or put the syscall in eax, push the others and put the pointer to the stack in ebx). Thx :)
Quoted 31 lines · John Rodriguez
I am still newbie myself, but one thing that I noticed is that you pass some parameters via registers and others via the stack pointer.
The write sys call takes 3 param (as you prob already know), the file descriptor (1 = stdout), the pointer to the buffer, and its size.
The write sys call itself is syscall 4.
According to http://asm.sourceforge.net/articles/linasm.html
"For all syscalls, the syscall number goes in %eax. For syscalls that have less than six args, the args go in %ebx,%ecx,%edx,%esi,%edi in order. The return value of the syscall is stored in %eax."Here is my own example that I wrote about a year ago.
section .data
hello db 'Hello, World!', 0Ah
len equ $-hellosection .text
global_start_start:mov edx, len mov ecx, hello mov ebx, 1 mov eax, 4 int 80h mov ebx, 0 mov eax, 1 int 80h
Hi,
in amd64, registers are different (64bits...) ;) So, I think you'd better use the 64 bits name version push rbp
mov rbp,rsp
...
What do you have as result in your case?
can you try it with gdb and step your prog?
Fred
Le Samedi 12 Novembre 2005 00:05, Lorenzo a écrit :
Quoted 39 lines
Hi,
i have some problems with my first linux/nasm asm program. This is a simple "hello world" program but i can't see the "hello world" on my screen and i don't find my error.
I work on 64bit amd system.
Someone can illuminate me? :)Thx
-----------------------------------
section .text
global_startmsg db 'hello, world!',0xa
len equ $ - msg
_start:push ebp mov ebp,esp push len push msg push 1 mov ebx,esp mov eax,4 int 0x80 add esp,12 mov ebx,0 mov eax,1 int 0x80-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Frederic Marmond - To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
When i back in office i try to use 64bit registers.
At home i have a linux distribution (slackware, 32bit) installed over a 64bit hardware and i can't try (i think that i can't try but is possible that i don't know how :)) For the gdb is the same thing, when back in office i try.
Thx :)
Quoted 13 lines · Frederic Marmond
Hi,
in amd64, registers are different (64bits...) ;) So, I think you'd better use the 64 bits name version push rbp
mov rbp,rsp
...What do you have as result in your case?
can you try it with gdb and step your prog?Fred