简体   繁体   中英

Assembler segmentation fault on dereference register address

I have a problem with x86 assembly (AT&T).

Because I need to implement an array lookup in assembler I have in the register %ebx the first item of the array (say arr[0]) and in order to point to arr[1] for example I wrote:

mov -4(%ebx), %eax

The problem is, I have a segmentation fault when I try to get the ebx's address, which is very strange because I can get the ebx's value (the value of arr[0]) without problems.. Some advices?

EDIT: Ok, I think I understood the error. When I declare the array I have to put on the variable arr the address of the first element:

mov -4(%ecx), %eax

But with this instruction i put the value not the address. So how can I put the address?

arr[1] is actually rather unlikely to be at -4[%ebx] , it far more likely to be at +4 .

But based on your question, I'm not sure you're understanding. That will only work if %ebx is the address of the first element in the array. Your text seems to indicate that you've loaded the value of arr[0] into ebx in which case, there's no way to get at the other elements from there.

You may need to post a little more code so that we can see what you're actually trying to do. Code generally trumps descriptive text for programming problems :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM