[英]linux nasm assembly endlessly printing character
我正在編寫一個程序來從用戶那里獲取一個整數,然后打印出從0到該數字的所有數字。 我的代碼可以很好地處理輸入,但是在將其打印出來時,它會連續不斷地循環打印。 這是我的代碼:
SECTION .data ; Constant variable declaration
len EQU 32 ; Constant length
msg db "Enter a number: ", 0 ; Input message
msglen EQU $-msg ; Input message length
SECTION .bss ; Uninitialised data declaration
other resd len ; Output counter that is incremented
data resd len ; Input data buffer
SECTION .text ; Main program initialiser
GLOBAL _start ; Linker entry point declaration
_start: ; Entry point
nop ; This keeps the debugger happy :)
Msg: ; This section prints out the message
mov eax, 4 ; }
mov ebx, 1 ; }
mov ecx, msg ; } System_write call
mov edx, msglen ; }
int 80h ; }
input: ; This section gets the integer from the user
mov eax, 3 ; }
mov ebx, 0 ; }
mov ecx, data ; } System_read call
mov edx, len ; }
int 80h ; }
ASCIIAdj:
mov ebp, 48 ; This line sets the counter to '0' ASCII
setup: ; This section adjusts the counter
mov [other], ebp ; Increment counter
loop: ; This section loops, printing out from zero to the number given
mov eax, 4 ; }
mov ebx, 1 ; }
mov ecx, other ; } System_write call
mov edx, len ; }
int 80h ; }
mov eax, 1 ; Move 1 to eax
add ebp, eax ; Add eax to ebp (essentially increment ebp)
mov eax, other ; move other to eax
mov ebx, data ; move data to ebx
cmp eax, ebx ; compare them
jne setup ; If they are not the same, go back to the setup to increment other
exit: ; Exits the program
mov eax, 1 ; }
mov ebx, 0 ; } System_exit call
int 80h ; }
為什么它不斷循環? 我增加了計數器,並比較了輸入和計數器,所以為什么不中斷?
提前致謝
編輯:預期的輸出:
Enter a number: 6
0123456
該程序的一般語義:
Display "Enter a number: "
Read in an integer less than 32 bytes in size.
Set a counter variable to the ASCII value of zero
Loop:
Display the character, adding 1 to it, and checking to see if it is equal to the value inputted.
If it is equal, goto the exit section and exit
Else loop.
這使我深深地陷入了我記憶中深沉的黑暗之中,但是我想你想要
mov eax, [other] ; move other to eax
mov ebx, [data] ; move data to ebx
請注意括號,您的代碼中缺少這些括號。 您正在將other
和data
的地址加載到eax
和ebx
,而不是其中包含的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.