Reputation: 623
I am going through "Programming from ground up". Now I have the following code, which should give 2 as minimum answer, but I am getting 0 as answer when I do echo $?.
.section .data
data_items:
.long 3,67,34,222,56,87,9,2,88,22,11,66,900,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
jg start_loop
movl %eax,%ebx
jmp start_loop
loop_exit:
movl $1,%eax
int $0x80
Upvotes: 2
Views: 287
Reputation: 11075
You're not printing the result. You need to debug. ebx will contain the answer after the loop has executed.
I know the int 0x80 means to call an external function, but I'm not sure what the details are there. Ok.. according to a nice page on interrupt 0x80 and system call numbers, the $1 is an exit code.
It dosn't seem like you're printing the result. Ok, the basic format of a print statement is this:
mov eax, <MEMORY POINTER TO STRING>
int 21h
You would need to convert your result into characters, put them in memory, and then pass in the memory location to the 'int 21h' call which will print them to the screen.
Try some of these examples and see if they work for you.
Can you debug the code to verify what's going on?
Upvotes: 0
Reputation: 20175
well, 0 is less than 2
Since you are JG'ing your going back to the loop if the value in eax is greater than the current ebx, also looks like the zero is used as an exit code in these lines
cmpl $0,%eax
je loop_exit
So in this case when you hit the zero in the list, it is effectively the lowest number AND the exit condition
Upvotes: 1