我一直試圖創建一個循環來打印一個字符的次數取決於用戶的輸入,但是,循環不停止,而是無限地進行。循環不斷循環
mov esi, [items] //Esi points to the first item - Calling data from the C code and assigning it to the esi source indexer, in this case being the users inputted number.
loop1: mov eax, [esi] // moves the first number which is in esi to the eax register
push eax // pushes it onto the stack so it can be used
call printInt // Prints the integer in the eax register
push ',' // Prints a comma after the number inputted
call printChar
push ' ' // Prints a space
call printChar
mov cx, 0 // assigning the value of 0 to counter
loop2:
push '*' // pushing the required character onto the stack
call printChar // printing the character
inc cx // incrementing the counter by 1
cmp cx, [esi] // comparing the program counter with the users inputted number
jne loop2 // jumping back to the beginning of the loop if cx is not equal to the users input thus printing the character the same number of times as the users inputted number
call printNewLine
mov eax, [esi]
add esi, 4 // Now that's odd. Esi is pointing at an integer, and that's 4 bytes in size.
cmp eax, 0
jnz loop1
jmp finish // We need to jump past the subroutine(s) that follow
// else the CPU will just carry on going.
該程序的輸入和輸出由C控制,這就是我爲帖子標記C的原因。
程序中不工作的部分應該是從loop2開始到jne loop2結束。
非常感謝您的幫助。
我不認爲C標籤在這裏是合理的.. –
好吧,我會刪除它。 – Jurdun
'printChar'可能會破壞你的'cx'計數器。學習使用調試器。還請閱讀ABI文檔。如果你是從C調用的,你應該遵循約定。 – Jester