Hey everyone,
I'm enjoying learning more about the under-hood of the computer.
There is something I don't quite understand.
Here is my program to find maximum using an end address.
.section .data
>
> #eax holds current value and exit status
> #ebx holds the highest value
> #edx holds the current index
> #edi holds the current address
>
> data_items:
> .long 3,204,5,6,0,1,55,30
> eol:
> .long 105
>
> .section .text
> .globl _start
>
> _start:
> movl $0, %edx
> movl data_items(,%edx,4), %eax
> movl %eax, %ebx
>
> loop:
> leal data_items(,%edx,4), %edi #move the current address to edi
> cmpl $eol, %edi #compare the current address
> to the eo
> *jg end*
>
> incl %edx
> movl data_items(,%edx,4), %eax
> cmpl %eax, %ebx
> jge loop
>
> movl %eax, %ebx
> jmp loop
>
>
> end:
> movl $1, %eax
> int $0x80
>
At the offending line, if I replace it with *je end*, the program works. If
I leave it as is, the exit status is 0, showing that the program did not
run even once. The reason I came to understand or diagnose is that the
value of *eol* is some value greater than 255 while %edi is, for the start
of the program after moving the address to it, less than 255. eol is then
seen as smaller than edi by the value that it overshoots 255 by hence the
program never runs through the rest of loop.
Now, my problem is, why? The only part in the book that referenced anything
like this said that only the *exit status* is allowed to be less than 256.
But why do longs overshoot? How then can I ever compute large numbers? *Unless
something is wrong with my code.*
Please help, Much appreciated.
_______________________________________________
Pgubook-readers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/pgubook-readers