Assembly 看起来我在MASM x86中进行了无限循环!我想我需要一些帮助来了解到底发生了什么
所以,我有我的代码,虽然我需要一些帮助,但我真正想要的是帮助理解它在做什么,而不是我希望它做什么。有人能告诉我阅读代码语言的详细情况吗Assembly 看起来我在MASM x86中进行了无限循环!我想我需要一些帮助来了解到底发生了什么,assembly,x86,masm,masm32,Assembly,X86,Masm,Masm32,所以,我有我的代码,虽然我需要一些帮助,但我真正想要的是帮助理解它在做什么,而不是我希望它做什么。有人能告诉我阅读代码语言的详细情况吗 fibSeq: mov ecx, userNum ;takes user number for loop count mov eax, 0 ;x = 0 mov ebx, 1 ;y = 1 fibSeq2: mov edx, eax ad
fibSeq:
mov ecx, userNum ;takes user number for loop count
mov eax, 0 ;x = 0
mov ebx, 1 ;y = 1
fibSeq2:
mov edx, eax
add edx, ebx ;sum = x + y
mov eax, ebx ;x = y
mov ebx, edx ;x = sum
mov edx, ebx
call writeint ;prints the value of fib seq
mov edx, OFFSET spaces ;adds five spaces inbetween each number
call writestring
mov eax, count ;moves count into eax register
add eax, 1 ;adds 1 to count
jmp divbyFive ;jump to check if count is divisible by 5
JMP done ;once ecx is 0, jmp should go to done
divbyFive: ;check if count is divisible by 5
mov edx, 0 ;clearing the edx register
mov eax, count ;moving count into eax
mov ecx, 5 ;count / 5
div ecx
cmp edx, 0 ;if the remainder = 0, jump to new line
JE newLine
JNE fibSeq2 ;otherwise go back to the sequence
newLine:
call crlf ;if the count is divisible by 5 with no remainder, prints a new line
jmp fibSeq2 ;afterwards, jumps back up to fibSeq2
loop fibSeq2
done:
现在它只是一次又一次地打印+1,但我想让它做的是打印斐波那契序列中的数字,直到ecx为0,然后每5位开始一行
例如:
01123
5 8 13 21 34
等等 此代码有几个问题
您应该在使用这些寄存器之前保存它们。(顺便说一句,您还应该保存ebx。)其中任何一个的优点是,当遵循大多数32位调用约定时,您调用的任何函数(例如writestring)都会保留它们。(但Irvine32函数通常使用自己的特殊调用约定保留除返回值以外的所有寄存器。)Irvine32通常保留除返回值以外的所有寄存器(如果有)。他们的调用约定是为尚不了解调用阻塞寄存器的asm新手设计的。他们试图将其用作循环计数器,但
loop fibSeq2
紧跟在jmp fibSeq2
之后,本身不是分支目标。i、 e.loop
是不可访问的,因此ecx
的唯一用途是作为除数的暂存寄存器/facepalmWell它有一半的用处,并且在OP删除无条件无限循环后将是相关的。哇,这不是唯一的jmp
。那里有一对背对背的jmp
指令。这已经到了一个地步,它甚至没有错,只是胡说八道。