assembly - 汇编计数器代码将永远无法工作或循环
问题描述
所以,我的目标是让循环通过 x 次运行并打印 msgTrue 直到计数器等于 0。从理论上讲,这应该有效。不过,我可能只是弄乱了寄存器。
comparesCounter:
cmp ah, 0 ;ah stores the amount of repetitions I want the code to go through
jne notNull ;jump if not true
jmp exit
notNull:
dec ah ;ah --
mov eax, 4 ;|
mov ebx, 1 ;|
mov ecx, msgTrue ;|>this code prints out what's stored in msgTrue
mov edx, len1 ;|
int 80h ;|
jmp comparesCounter ;jumps up into counter
我是否应该使用其他寄存器,或者仅仅是我的代码的愚蠢程度超出帮助的概念?
解决方案
问题是修改eax
也会修改ah
. ah
这是一个简单的图表,显示和之间的关系eax
:
eax
--------------------------
| | ax |
| | ----------- |
| | | ah | al | |
| | ----------- |
---------------------------
3 2 1 0
如您所见,ah
是 的最重要的一半ax
,而后者又是 的最不重要的一半eax
。所以当你设置时eax = 4
,你是在隐式设置ah = 0
。
如果你想继续使用ah
循环计数器,你可以将它暂时放在堆栈上:
push eax ; Save eax's current value on the stack
mov eax, 4
...
int 80h
pop eax ; Restore eax from the stack
推荐阅读
- .net-3.5 - Windows Server 2019 中的 NetFx3 安装
- javascript - 如何.deferReply 到指定频道?
- reactjs - 有没有办法通过与另一个数组进行比较来绑定表中的名称而不是 id
- java - AnyLogic内存错误:如何知道超出阈值多少?
- python - pyspark 数据框使用列名制作地图值
- javascript - 在 Redux 中从 Supabase 获取数据,给了我一个我无法解决的 Promise
- c# - 如何使用 resourcekey Google Drive API 获取文件?
- java - 通缉但未调用:
实际上,与此模拟的交互为零 - css - 如何仅使用 CSS 向我的 b 表添加圆角边框
- flutter - Flutter DateTime 忽略夏令时的本地时间加减