I just started learning Assembly using Linux GNU and I am in the beginning stages to learning. Below is an simple code used in the book "Programming from the Ground up".
.section .data
data_items:
.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
.section .text
.globl _start
_start:
movl $0, %edi
movl data_items(,%edi,4), %eax
movl %eax, %ebx
start_loop:
cmpl $0, %eax
je loop_exit
incl %edi
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax
jle start_loop
movl %eax, %ebx
jmp start_loop
loop_exit:
movl $1, %eax
int $0x80
We're working on indirect addressing mode. I'm trying to modify this program to change the first value in the array to be the largest value (without, of course, changing the first data values in the code. Currently, the max value is 222. I tried to put an indirect address mode for line 9 from
movl %eax, %ebx
%ebx, %eax
to
movl (%eax), %ebx
%ebx, (%eax)
I assembled, linked, and ran the code, and the result was
Segmentation fault (core dumper)
and after echo $?
, I got the value 139
.
I read that "Segmentation fault" means that you tried to access memory that you do not have access to. I'm just trying to understand how to change the first number to be the max value in the array.
Sorry, I'm just starting with this.
Update: I solved it on my own. It's in the comment below.