Assembly x86 - status code not shown as defined

22 Views Asked by At

I have this code I've written in Assembly x86:

.section .data
  list: .long 1, 2, 3, 4, 5, 0
.section .text
.globl _start

_start:
  movl $0,%eax # eax will save our current location
  movl list(,%eax,4),%edi
  movl %edi,%ebx # ebx will save the biggest number since it's the beginning - edi is the biggest

cmpLoop:
  cmp $0,%edi
  je printBiggestNum

  incl %eax
  movl list(,%eax,4), %edi
  cmp %ebx,%edi
  jg setNewBiggestNum

setNewBiggestNum:
  movl %edi,%ebx
  jmp cmpLoop

printBiggestNum:
  movl $1,%eax
  int $0x80

As you can see, at the end of the function printBiggestNum, %ebx should already be equal to $5, and because it's also the register that determines the status code - the status code should be 5 too. But the fact is that the status code is 0. If I'm adding the line: movl $5,%ebx It of course works.

I cannot determine why this is happening and I would love to hear your solution for that.

(Also it's important to mention that I debugged this code (with gdb) and it really doing 5 loops and then calling the function printBiggestNum and exits after that, so no way it returns back after that or something like that).

Thanks a lot!

0

There are 0 best solutions below