assembly - 在汇编中有效地存储数据并使用它进行计算
问题描述
最近我开始学习组装,这是一段旅程!:) 我知道一些基本的东西,我想通过重新创建我的 python 程序来了解数据存储。该程序应该接受一个输入(我不确定在组装中是否可能)并返回九头蛇在一定天数后将拥有的头数。公式:result = ((old_day*new_day)+(new_day-old_day))
我已将我的 python 代码简化为:
old_day = 2
new_day = 3
fight = 5
temp1 = 0
temp2 = 0
temp3 = 0
for i in range(fight):
temp1 = old_day*new_day
temp2 = new_day-old_day
temp3 = temp1+temp2
old_day = new_day
new_day = temp3
print(old_day)
到目前为止,我在汇编中提出了这个:
global _start
section .data
old dw 2
l_old equ $ - old
new dw 3
l_new equ $ - new
tem1 dw 0
l_tem1 equ $ - tem1
tem2 dw 0
l_tem2 equ $ - tem2
tem3 dw 0
l_tem3 equ $ - tem3
days dw 4
section .text
_start:
mov al, [old]
mov bl, [new]
mov cl, [tem1]
mov dl, [tem2]
mov ah, [days]
mov eax, 1
mov ebx, 0
int 0x80
label:
我被困在标签上,因为mul
将其结果存储在其中,aex
但我将我的值存储在al
and中ah
。我的问题是:会mul
覆盖我的数据吗?有没有更好的数据存储方式?最后,我是否需要所有行,equ
或者仅在输出时才相关?感谢您的时间和帮助:)
解决方案
推荐阅读
- java - 来自 Set.of(...) 的随机迭代顺序
- python - 迭代df列列表并用字典中的值替换现有键有效python
- c++ - 理解operator()(函数对象)的使用
- python - 计算列表中的第一个数字,如二十一点纸牌游戏
- php - 如何仅通过一个查询从 mysql 数据库中获取多个数据?
- java - 在 JSP 页面中使用 request.getRealPath("/") 时出错
- c++ - 尝试构建 hello world 程序时从 QtCreator 获取错误消息,但代码仍然可以执行
- python - 从扩展用户模型中获取值错误
- laravel - 如何在现有项目中使用 Backpack for Laravel?
- reactjs - 为什么我不断收到 500(内部服务器错误)GET http://localhost:3000/favicon.ico 500(内部服务器错误)?