Assembler Developer

Moderators: None (Apply to moderate this forum)
Number of threads: 960
Number of posts: 1751

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
linux nasm assembly prints out random characters Posted by rileyh on 13 Oct 2012 at 1:23 AM
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. 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 ; }

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.

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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.