所以,我的目标是让循环通过x运行并打印msgTrue,直到计数器等于零。从理论上讲,这应该有效。不过,我可能只是弄乱了寄存器。
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