pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pgubook-readers] functions


From: George Nyoro
Subject: Re: [Pgubook-readers] functions
Date: Sat, 11 Jan 2014 13:04:49 +0300

I have discovered a bit more. I saw people using gdb to debug their programs so I decided to try too.
Some info: My comp is Intel core i3 64-bit architecture. So, apart from what the book has taught, some googling showed me that longs and pointers in this are 8 bytes long.
So, anyway, the problem I identified by running steps in gdb was in the conversion between esp and ebp. I don't know why, but for some reason, the value moved is different. Stripped, if I may say. Check this out:
from gdb,
Before executing movl %esp, %ebp : %esp has the value 0x7fffffffdf30   (esp is called rsp on mine) and ebp has the value 0x0.
After, %esp has the value 0x7fffffffdf30   (%esp is called %rsp on mine) and ebp has the value 0xffffdf30. That 7 is not carried over for some reason.
After doing the reverse, movl %ebp, %esp , both %ebp and %esp end up with the value 0xffffdf30. So, the initial value is not restored.
Trying to execute the next step gives a segmentation fault since clearly I am trying to access memory in an address that may well be outside assigned memory.
Any help?


On 11 January 2014 12:20, George Nyoro <address@hidden> wrote:
Hey again,
Sorry for the barrage of questions.
I am now trying function power. But I am getting segmentation faults with my own code and couldn't trace the error so I tried to reduce it till I could locate it.
The reduced format is this:

.code32
.section .data
.section .text
.globl _start

_start:
    pushl $3
    pushl $2
    call power
    movl %eax, %ebx
    addl $8, %esp
    movl $1, %eax
    int $0x80

.type power,@function
power:
pushl %ebp
movl %esp, %ebp

movl %ebp, %esp
popl %ebp
movl $5, %eax
ret

When I remove the line in bold, it compiles alright and gives me the right result but when I include the offending line, it gives me an error of segmentation fault. Why does this happen? Does it mean my processor does not allow one to directly manipulate the %esp value?
Thanks again.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]