[英]linux nasm assembly endlessly printing character
I am writing a program to get an integer from the user, and then print out all the numbers from 0 up to the number. 我正在编写一个程序来从用户那里获取一个整数,然后打印出从0到该数字的所有数字。 My code gets the input fine, but when printing it out, it prints continuously in what seems to be an endless loop. 我的代码可以很好地处理输入,但是在将其打印出来时,它会连续不断地循环打印。 Here is my code: 这是我的代码:
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 ; }
Why does it loop continuously? 为什么它不断循环? I have incremented the counter, and compared the input and the counter, so why doesn't it break? 我增加了计数器,并比较了输入和计数器,所以为什么不中断?
Thanks in advance 提前致谢
EDIT: Expected Output: 编辑:预期的输出:
Enter a number: 6
0123456
General Semantics of the program: 该程序的一般语义:
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.
This is digging waaaay back into the deep dark recesses of my memory, but I think you want 这使我深深地陷入了我记忆中深沉的黑暗之中,但是我想你想要
mov eax, [other] ; move other to eax
mov ebx, [data] ; move data to ebx
Note the brackets, which are missing in your code. 请注意括号,您的代码中缺少这些括号。 You are loading the addresses of other
and data
into eax
and ebx
, not the values contained there. 您正在将other
和data
的地址加载到eax
和ebx
,而不是其中包含的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.