Author Topic: Problem ... :|  (Read 2267 times)

Tobiasz Grotowski

  • Guest
Problem ... :|
« on: October 02, 2009, 09:17:03 PM »
Ok guys I have big problem... I back in to assembler programing today but I cant start ...

What is problem ? Look this:

I make any file, for ex. `vi ./test.asm`
and code: `section .text
global _start
_start:
mov 5, EAX`
now compling:  `nasm -f elf hello.asm`
and link: `ld -o hello hello.o`
if i try run this I get error: `segmentation fault`
WHY ? ? ? ? ?  -.-

I cant compiling/runig all of my *.asm ...
My OS is DEBIAN v503 (amd64)

If you know what I do wrong, please tell me ... :S Thanks in advance.

BTW: I tested it on another machine and got same error .. (there was Debian too..)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2384
  • Country: us
Re: Problem ... :|
« Reply #1 on: October 02, 2009, 10:12:34 PM »
C'mon Tobsik, show us the real code! Nasm won't get past "mov 5, eax"!!! :)

Try:

global _start

section .text

_start:

mov edx, msg_len ; length

mov ecx, msg ; buffer

mov ebx, 1 ; file descriptor STDOUT

mov eax, 4 ; __NR_write

int 80h

; now exit the application!

mov eax, 1 ; __NR_exit

int 80h

section .data

msg db "Hello, Debian!", 10

msg_len equ $ - msg

Most likely, your segfault is from failing to exit cleanly, although there are other causes... Hang in there, you'll find 'em. :)

Best,
Frank

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2384
  • Country: us
Re: Problem ... :|
« Reply #2 on: October 02, 2009, 10:18:46 PM »
Whoa! Just noticed your OS is 64-bit! You'll have to tell your (64-bit) ld, "-melf-i386" (I think that's correct) to let it know we're doing 32-bit code... OR tell Nasm "-f elf64", and change your code to suit - 64-bit code is different! A lot! I suggest you stick to 32-bit code, to start with.

Best,
Frank

Tobiasz Grotowski

  • Guest
Re: Problem ... :|
« Reply #3 on: October 03, 2009, 01:27:28 PM »
Yep, **fbkotler** You have right my OS is 64 and this is problem.
However I try use: ld -m elf_i386 and I get the same error ... :( `segmentation fault`
Any idea..? I would be very grateful for help..

Best, Tobsik