* Very newbie question...
@ 2005-11-11 23:05 Lorenzo
2005-11-11 23:16 ` John Rodriguez
2005-11-11 23:29 ` Frederic Marmond
0 siblings, 2 replies; 7+ messages in thread
From: Lorenzo @ 2005-11-11 23:05 UTC (permalink / raw)
To: linux-assembly
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
^ permalink raw reply [flat|nested] 7+ messages in thread* RE: Very newbie question... 2005-11-11 23:05 Very newbie question Lorenzo @ 2005-11-11 23:16 ` John Rodriguez 2005-11-12 1:04 ` Brian Raiter 2005-11-12 7:34 ` Lorenzo 2005-11-11 23:29 ` Frederic Marmond 1 sibling, 2 replies; 7+ messages in thread From: John Rodriguez @ 2005-11-11 23:16 UTC (permalink / raw) To: 'Lorenzo', linux-assembly 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: linux-assembly-owner@vger.kernel.org [mailto:linux-assembly-owner@vger.kernel.org] On Behalf Of Lorenzo Sent: Friday, November 11, 2005 6:05 PM To: linux-assembly@vger.kernel.org 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Very newbie question... 2005-11-11 23:16 ` John Rodriguez @ 2005-11-12 1:04 ` Brian Raiter 2005-11-12 7:35 ` Lorenzo 2005-11-12 7:34 ` Lorenzo 1 sibling, 1 reply; 7+ messages in thread From: Brian Raiter @ 2005-11-12 1:04 UTC (permalink / raw) To: linux-assembly > 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Very newbie question... 2005-11-12 1:04 ` Brian Raiter @ 2005-11-12 7:35 ` Lorenzo 0 siblings, 0 replies; 7+ messages in thread From: Lorenzo @ 2005-11-12 7:35 UTC (permalink / raw) To: linux-assembly Ah ok... now i understand some more things :) Thx :) Brian Raiter wrote: >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 >- >To unsubscribe from this list: send the line "unsubscribe linux-assembly" in >the body of a message to majordomo@vger.kernel.org >More majordomo info at http://vger.kernel.org/majordomo-info.html > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Very newbie question... 2005-11-11 23:16 ` John Rodriguez 2005-11-12 1:04 ` Brian Raiter @ 2005-11-12 7:34 ` Lorenzo 1 sibling, 0 replies; 7+ messages in thread From: Lorenzo @ 2005-11-12 7:34 UTC (permalink / raw) To: linux-assembly 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 :) John Rodriguez wrote: >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 > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Very newbie question... 2005-11-11 23:05 Very newbie question Lorenzo 2005-11-11 23:16 ` John Rodriguez @ 2005-11-11 23:29 ` Frederic Marmond 2005-11-12 7:35 ` Lorenzo 1 sibling, 1 reply; 7+ messages in thread From: Frederic Marmond @ 2005-11-11 23:29 UTC (permalink / raw) To: Lorenzo; +Cc: linux-assembly 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 : > 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 majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Frederic Marmond - To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Very newbie question... 2005-11-11 23:29 ` Frederic Marmond @ 2005-11-12 7:35 ` Lorenzo 0 siblings, 0 replies; 7+ messages in thread From: Lorenzo @ 2005-11-12 7:35 UTC (permalink / raw) To: linux-assembly 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 :) Frederic Marmond wrote: >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 > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-11-12 7:35 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2005-11-11 23:05 Very newbie question Lorenzo 2005-11-11 23:16 ` John Rodriguez 2005-11-12 1:04 ` Brian Raiter 2005-11-12 7:35 ` Lorenzo 2005-11-12 7:34 ` Lorenzo 2005-11-11 23:29 ` Frederic Marmond 2005-11-12 7:35 ` Lorenzo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).