从头开始编程的挑战之一是“修改程序以使用结束地址而不是数字 0 来知道何时停止。”
\n我发现很难做到这一点,因为到目前为止,这本书只介绍了movl,,cmpl(incl以及寻址模式)和jmp指令。基本上,下面的代码片段中的所有内容都是到目前为止所介绍的。我发现的所有解决方案都涉及本书中尚未介绍的说明。下面的代码查找集合中的最大值。
.section .data\ndata_items: #These are the data items\n.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0\n\n.section .text\n.globl _start\n_start:\n movl $0, %edi # move 0 into the index register\n movl data_items(,%edi,4), %eax # load the first byte of data\n movl %eax, %ebx # since this is the first item, %eax is\n # the biggest\nstart_loop: # start loop\n cmpl $0, %eax # check to see if we\xe2\x80\x99ve hit the end\n je loop_exit\n incl %edi # …Run Code Online (Sandbox Code Playgroud)