NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: EGD Eric on March 27, 2010, 12:48:53 AM
-
Hi, I've searched for information on segmentation faults, but haven't found much applicable to my situation, so I was wondering if there was something obvious in my hello world here that is causing a segmentation fault that you could see.
This program asks for the user's name, then says: "hello", then the user's name. Pretty fancy, here it is:
Segment .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, prompt1
mov edx, len1
int 0x80 ;print: "plz enter your name"
mov eax, 3
mov ebx, 0
mov ecx, name
mov edx, 200
int 0x80 ;get input,
mov esi, eax
mov eax, 4
mov ebx, 1
mov ecx, prompt2
mov edx, len2
int 0x80
mov ecx, name
mov edx, esi
int 0x80
Segment .data
prompt1 db "plz Enter your name", 10
len1 equ $-prompt1 ;length of the string: $-prompt1
prompt2 db "Hello "
len2 equ $-prompt2
Segment .bss
name resb 200
What it ends up doing is just asking for your name, then once you give it, it says: hello segmentation fault.
-
What's the very first sys_call? Hint: you should do it last! :)
There's another problem, though...
...
mov esi, eax ; save length of input
mov eax, 4
mov ebx, 1
mov ecx, prompt2
mov edx, len2
int 0x80
; at this point, ebx is still STDOUT, but eax is number
; of bytes printed - reload it with sys_write.
mov ecx, name
mov edx, esi
int 0x80
...
Best,
Frank