i am working on an asm tutorial book, and the second sample program will not work for me
it is linux assembler and this code is supposed to return the largest value in a list
the first time i ran it it returned 250, and after some changes it returns 136, i dont know why
Code:# PURPOSE: Find a maximum value form a set of # data items. # # VARIABLES: Registers: # # %edi - Holds the index of the item being examined # %ebx - Larges data item found # %eax - Current data item # # Memory locations: # # data_items - Contains the item data. A 0 is used # as the end value # .section .data data_items: #The data items .long 3,56,43,65,200,1,506,943,32,4,90,5000,78,0 .section .text .globl _start _start: movl $0, %edi #set the position to 0 movl data_items(,%edi,4), %eax #load the first byte of data movl %eax, %ebx #since it is the first item it is automatically the biggest start_loop: cmpl $0, %eax #check if the end has been reached je loop_exit incl %edi #set to next data value movl data_items(,%edi,4), %eax #load the current data value cmpl %ebx, %eax #compare the values jle start_loop #next loop iteration if the new value is not bigger movl %eax, %ebx #otherwise replace the largest value jmp start_loop #restart loop loop_exit: # %ebx now holds the highest vlaue and will be returned as a status\ # after an exit system call movl $1, %eax #set exit system call int $0x80 #run system call



Reply With Quote