0

My code to find the largest value:

# %edi - Holds the current index
# %ebx - Largest element so far
# %eax - Current element

.section .data

    data_items:
        .int 3,67,34,222,45,75,65,55,45,35,100,300,0
.section .text

.global _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

The output of this code: echo $? is getting printed as 44. But when I debug it using gdbtui I am getting the value 300 in %ebx. Then why is it corrupting the value of %ebx while calling the program exit interrupt?

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68

0 Answers0