Discussion:
simple ASM prog segfault
(too old to reply)
Xavier Maillard
2019-11-26 06:12:43 UTC
Permalink
Hello,

I am just starting to learn writing some fun progs in asm.

I just jotted down some instructions, assembled it and linked it.
Running it just segfault.

The question is: why ? :)

The program is just this:

.section .data

.section .text
.globl _start
_start:

movl $1, %eax
movl $0, %ebx
int $0x80

As you can see, it just does *nothing*

Assembled it using: as
Linked it with ld

This is running on a WSL Debian system (should matter I guess)

Any pointer on what's wrong with this ?

Thanks.

N.B: I am just an amateur and I do not plan writing serious things atm, just having fun :)
--
- xma

GPG: BA4909B7 8F04DE1B
Bart
2019-11-26 20:15:00 UTC
Permalink
Post by Xavier Maillard
Hello,
I am just starting to learn writing some fun progs in asm.
I just jotted down some instructions, assembled it and linked it.
Running it just segfault.
The question is: why ? :)
.section .data
.section .text
.globl _start
movl $1, %eax
movl $0, %ebx
int $0x80
As you can see, it just does *nothing*
Syscall #1 appears to do 'exit', so it /ought/ to do nothing!

Are you saying it crashes instead of gracefully exiting?

Is your system 64 bits? If so you might try using rax and rbx instead of
eax and ebx. However I don't know whether the 64-bit set of syscalls are
the same (one set I saw appeared to be different from the 32-bit ones.
eg call #1 does sys_write).

(I know nothing about Linux assembly coding, it just looked intriguing.)

If you can't get anywhere, try starting from C and write the simplest
program. Compile it like this:

gcc -S prog.c

to get the assembly output in prog.s, which can also be assembled and
linked by gcc (which will invoke as and ld, or you can do that yourself):

gcc prog.s -oprog

Now you can play with the ASM instructions in prog.s, but starting from
something that works.
Melzzzzz
2019-11-26 21:06:00 UTC
Permalink
Post by Xavier Maillard
Hello,
I am just starting to learn writing some fun progs in asm.
I just jotted down some instructions, assembled it and linked it.
Running it just segfault.
The question is: why ? :)
.section .data
.section .text
.globl _start
movl $1, %eax
movl $0, %ebx
int $0x80
As you can see, it just does *nothing*
Assembled it using: as
Linked it with ld
This is running on a WSL Debian system (should matter I guess)
Any pointer on what's wrong with this ?
It's probably because you assembled and linked with 64 bits.
You should specify 32 bits...
--
press any key to continue or any other to quit...
U ničemu ja ne uživam kao u svom statusu INVALIDA -- Zli Zec
Svi smo svedoci - oko 3 godine intenzivne propagande je dovoljno da jedan narod poludi -- Zli Zec
Na divljem zapadu i nije bilo tako puno nasilja, upravo zato jer su svi
bili naoruzani. -- Mladen Gogala
Loading...