Skip to content
Advertisement

Why does my assembly program give segfault?

I have the following piece of code that I have to debug:

JavaScript

After compiling and running that code I obtain a segmentation fault error, it seems that something goes wrong after the 5th line. My linux asm knowledge is very basic, any hints or ideas about what is exactly going wrong and how to fix it?

This piece of code is a part of a debugging exercise, I’m doing that for auto-learning only, this is not a part of any homework or something.

Advertisement

Answer

I have compiled your example and then looked at it using hexdump:

(I had to add BITS 32 to it to compile in 32-bit mode, because I’m using Linux-64):

JavaScript

Do you see the pattern? At the right column (ASCII mode) you can see a lot of literal xNN, that is not the byte NN but the characters '' 'x' and two numbers!

My guess is that you are debugging a dump of some binary code, but that code has not been properly dumped. Thus the assembly you are looking at is nonsense.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement