flat assembler
Message board for the users of flat assembler.
Index
> Linux > What's causing this seg fault? |
Author |
|
binary108 26 May 2004, 12:04
May be you must write
_start: pop ebp ;argc dec ebp ;!!!! But i'm not sure |
|||
26 May 2004, 12:04 |
|
Ashy 26 May 2004, 13:06
That is happening anyway.
Are u saying that maybe the 'dec ebp' should come straight after 'pop ebp' ? Would this make a difference? |
|||
26 May 2004, 13:06 |
|
Tomasz Grysztar 26 May 2004, 13:41
You were trying to display one more argument more than you had.
Here's the corrected version that can be compiled with fasm directly to executable: Code: format ELF executable pop ebp ;argc pop ecx ;get program name off stack argument: dec ebp ;minus the last argument jz exit pop ecx ;get argument mov ebx,ecx xor edx,edx strlen: mov al,[ebx];get a byte of the argument inc edx ;increment the char counter inc ebx ;increment the address ptr test al,al ;see if char was zero jnz strlen mov byte [ebx-1],10 ;tag on a line break ;write to stdout mov eax,4 ;write syscall mov ebx,1 ;to stdout int 80h ;call kernel jmp argument exit: mov eax,1 ;exit syscall mov ebx,0 ;return success int 80h ;call kernel And here's the version which fasm will compile into an object file, which you can then link into final executable with gcc or ld command: Code: format ELF section '.text' executable public _start _start: pop ebp ;argc pop ecx ;get program name off stack argument: dec ebp ;minus the last argument jz exit pop ecx ;get argument mov ebx,ecx xor edx,edx strlen: mov al,[ebx];get a byte of the argument inc edx ;increment the char counter inc ebx ;increment the address ptr test al,al ;see if char was zero jnz strlen mov byte [ebx-1],10 ;tag on a line break ;write to stdout mov eax,4 ;write syscall mov ebx,1 ;to stdout int 80h ;call kernel jmp argument exit: mov eax,1 ;exit syscall mov ebx,0 ;return success int 80h ;call kernel |
|||
26 May 2004, 13:41 |
|
Ashy 26 May 2004, 14:16
Thanks Privalov
fasm seems to take the same syntax as nasm except for the section declerations. Is this correct? I guess ill have a more in depth look at fasm.txt. I didnt see anything about that when i perused it the first time around. |
|||
26 May 2004, 14:16 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.