- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我一直在阅读“从头开始编程”一书来学习 Linux 中的汇编编程。我无法解决第 3 章末尾的一个练习。练习说要修改以下程序以使用数据集末尾的地址来终止循环。这只是一个简单的程序,用于查找一组数据中的最大数,目前它仅使用数字零来标记数据的结尾。
#PURPOSE: This program finds the maximum number of a
# set of data items.
#
#VARIABLES: The registers have the following uses:
#
# %edi -- Holds the index of the data item being examined
# %ebx -- Largest data item found
# %eax -- Current data item
#
# The following memory locations are used:
#
# data_items -- Contains the item data. A 0 is used
# to terminate the data.
#
.section .data
data_items:
.long 3, 67, 34, 14, 45, 75, 54, 187, 44, 87, 22, 11, 66, 0
.section .text
.globl _start
_start:
movl $0, %edi # Move 0 into the index register
movl data_items (, %edi, 4), %eax # Load the first byte of data
movl %eax, %ebx # The biggest
start_loop:
cmpl $0, %eax # Check to see if we've hit the end
je loop_exit
incl %edi # Load next value
movl data_items (, %edi, 4), %eax
cmpl %ebx, %eax # Compare values
jle start_loop # Jump to the beginning if new value
# Isn't larger
movl %eax, %ebx # Move the value as the largest
jmp start_loop # Jump to the beginning of loop
loop_exit:
# %ebx is the status code for the exit system call
# and it contains the maximum number
movl $1, %eax # 1 is the exit() system call
int $0x80
我知道我可以只对数据列表的长度进行硬编码,或者我可以将它存储在数据的第一个字节中,但是练习要求使用最后一个元素的地址来终止循环。书中提到使用符号来标记结束。我认为我的问题是我只是不明白如何获取地址。如果我知道如何得到它,我可以将它存储在寄存器中。感谢您的帮助。
最佳答案
针对 Mac OSX 进行了一些小修改...
.data
data_items:
.long 3, 67, 34, 14, 45, 75, 54, 187, 44, 87, 22, 11, 66, 0
data_end:
.text
.globl start
start:
movl $0, %edi # Move 0 into the index register
movl data_items (, %edi, 4), %eax # Load the first data value
movl %eax, %ebx # The biggest
leal data_end, %ecx # Load and save ending address
start_loop:
leal data_items(, %edi, 4), %eax # Get address of next value
cmpl %eax, %ecx # Check to see if we've hit the end
je loop_exit
incl %edi # Increment index
movl (%eax), %eax # Load value
cmpl %ebx, %eax # Compare values
jle start_loop # Jump to the beginning if new value
# Isn't larger
movl %eax, %ebx # Move the value as the largest
jmp start_loop # Jump to the beginning of loop
loop_exit:
movl $1, %eax # 1 is the exit() system call
pushl %ebx
pushl $0
int $0x80
关于linux - 获取一组数据末尾的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12874611/
我正在更改链接网址以添加 www.site.com/index.html?s=234&dc=65828 我通过此代码得到的是:site.com/&dc=65828 var target="&dc=65
我在编译过程中收到错误: src/smtp.c:208:1: warning: control reaches end of non-void function [-Wreturn-type] 这是相
这是我的 bootstrap/html 代码: Put email 位置正确,但我希望输入字段的大小延伸到 div 末尾。谁能帮帮我? 最佳答案 只需按百分比指定宽度,如下所示
我正在尝试获取一个像这样的 json 对象: filters = {"filters": myArray}; 并将其附加到 URL 的末尾,使用: this.router.navigate([`/de
这个问题已经有答案了: Remove hash from url (5 个回答) 已关闭 10 年前。 我有一个网站,stepaheadresidents.com ,并且井号 (#) 会自动添加到 u
我有这个代码 $('container a').appendTo('.container'); dzedzdqdqdqzdqdzqdzqdqzdqd Forgot password
为了练习更多 Python 知识,我尝试了 pythonchallenge.com 上的挑战 简而言之,作为第一步,此挑战要求从末尾带有数字的 url 加载 html 页面。该页面包含一行文本,其中有
我对 FS2 很陌生,需要一些有关设计的帮助。我正在尝试设计一个流,它将从底层的 InputStream 中提取 block ,直到结束。这是我尝试过的: import java.io.{File,
我对 FS2 很陌生,需要一些有关设计的帮助。我正在尝试设计一个流,它将从底层的 InputStream 中提取 block ,直到结束。这是我尝试过的: import java.io.{File,
我正在编写一个 ajax 应用程序,并且在 php 脚本中有一个函数: public function expire_user() { $r=array("return"=>'OK');
我正在使用一个QListView,它包装了一个非常简单的列表模型。我想尝试实现类似于某些网页中看到的“无限滚动”的东西。 目前,模型通过最多添加 100 个项目的方法更新(它们取自外部 Web API
运行 cucumber 测试给我以下错误 end of file reached (EOFError) /usr/lib64/ruby/2.0.0/net/protocol.rb:153:in
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我想知道版本命名的具体作用是什么? 喜欢 jquery.js?ver=1.4.4 我的意思是如果我使用像这样的 cdn jquery/1.4.4/jquery.min.js?ver=1.4.4但是另一
" data-fancybox-group="gallery" title="">" alt="" /> 在此代码中 echo $prod['item_image_url'];打印存储在我的表中的图像
我目前使用 Wordpress 作为博客平台,但我想更改为使用 Jekyll 来生成静态页面。在 WordPress 上,我的 URL 使用以下格式: /年/月/日/标题 但我想将其重定向到 /年/月
根据docs这应该是不可能的 Regular expressions cannot be anchored to the beginning or end of a token 尽管如此,它似乎对我有
有没有办法创建 dijit 并将其附加到 div 的末尾?假设我有以下代码: Add Person 我在网上找到了以下代码,但这替换了我的“attendants”div: var personCo
我有这段代码: //execute post (the result will be something like {"result":1,"error":"","id":"4da775
我需要一些函数方面的帮助。 我想编写一个插入链表的函数。但不仅仅是中间,如果必须插入前端或末尾,它也必须起作用。 结构: typedef struct ranklist { i
我是一名优秀的程序员,十分优秀!