Note that there are some explanatory texts on larger screens.

plurals
  1. POMaximum of a list of long values in assembly
    primarykey
    data
    text
    <p>I've been recently working towards learning a bit of assembly and I'm currently stumped on an exercise which requires me to find the maximum number of a list of long values.</p> <p>The code is as follows:</p> <pre><code>.section .data data_items: .long 200, 201, 101, 10, 0 min_val: .long 0x8000000000000000 # MIN_VALUE in long .section .text .global _start _start: movl $0, %edi # init counter to 0 movl min_val, %ebx start_loop: cmpl $0, %eax je loop_exit # go to end if 0 encountered incl %edi movl data_items(,%edi,4), %eax cmpl %ebx, %eax jle start_loop # if new value &lt; max value in ebx, read next element movl %eax, %ebx jmp start_loop loop_exit: movl $1, %eax int $0x80 </code></pre> <p>Two problems with this code:</p> <ul> <li>When trying to assemble the code, I get the message: <strong><em>Warning: value 0x8000000000000000 truncated to 0x0</em></strong></li> <li>If I rewrite my code in an alternative logic (one which doesn't require min_value variable), any value greater than 255 in the list of data_items is truncated or returned as value % 256 even though the range of <code>.long</code> should be much larger?</li> </ul> <p>Can anyone help me understand what I'm doing wrong?</p> <p><strong>EDIT:</strong> After changes, the code looks like below. Note how maximum in this case turns out to be 145 instead of 401.</p> <pre><code>.section .data data_items: .long 401, 201, 101, 10, 0 max_val: .long 0x80000000 .section .text .global _start _start: movl $0, %edi # init counter to 0 movl max_val, %ebx start_loop: movl data_items(,%edi,4), %eax cmpl $0, %eax je loop_exit # go to end if 0 encountered incl %edi cmpl %ebx, %eax jle start_loop # if new value &lt; max value in ebx, read next element movl %eax, %ebx jmp start_loop loop_exit: movl $1, %eax int $0x80 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload