<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'linux nasm assembly prints out random characters' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'linux nasm assembly prints out random characters' posted on the 'Assembler Developer' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 11:17:11 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 11:17:11 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>linux nasm assembly prints out random characters</title>
      <link>http://www.programmersheaven.com/mb/pharabee/429798/429798/linux-nasm-assembly-prints-out-random-characters/</link>
      <description>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:&lt;br /&gt;
&lt;br /&gt;
    SECTION .data           ; Constant variable declaration&lt;br /&gt;
        len   EQU 32        ; Constant length&lt;br /&gt;
        msg db "Enter a number: ", 0 ; Input message&lt;br /&gt;
        msglen EQU $-msg             ; Input message length&lt;br /&gt;
&lt;br /&gt;
SECTION .bss            ; Uninitialised data declaration&lt;br /&gt;
        other resd len      ; Output counter that is incremented&lt;br /&gt;
        data  resd len      ; Input data buffer &lt;br /&gt;
&lt;br /&gt;
SECTION .text           ; Main program initialiser&lt;br /&gt;
&lt;br /&gt;
GLOBAL _start           ; Linker entry point declaration&lt;br /&gt;
_start:                 ; Entry point&lt;br /&gt;
        nop                 ; This keeps the debugger happy :)&lt;br /&gt;
&lt;br /&gt;
Msg:                    ; This section prints out the message&lt;br /&gt;
        mov eax, 4          ; }&lt;br /&gt;
        mov ebx, 1          ; }&lt;br /&gt;
        mov ecx, msg        ; } System_write call&lt;br /&gt;
        mov edx, msglen     ; }&lt;br /&gt;
        int 80h             ; }&lt;br /&gt;
&lt;br /&gt;
input:                  ; This section gets the integer from the user&lt;br /&gt;
        mov eax, 3          ; }&lt;br /&gt;
        mov ebx, 0          ; }&lt;br /&gt;
        mov ecx, data       ; } System_read call&lt;br /&gt;
        mov edx, len        ; }&lt;br /&gt;
        int 80h             ; }&lt;br /&gt;
&lt;br /&gt;
ASCIIAdj:   &lt;br /&gt;
        mov ebp, 48         ; This line sets the counter to '0' ASCII&lt;br /&gt;
&lt;br /&gt;
setup:                  ; This section adjusts the counter&lt;br /&gt;
        mov [other], ebp    ; Increment counter &lt;br /&gt;
&lt;br /&gt;
loop:                   ; This section loops, printing out from zero to         the number given&lt;br /&gt;
        mov eax, 4          ; }&lt;br /&gt;
        mov ebx, 1          ; }&lt;br /&gt;
        mov ecx, other      ; } System_write call&lt;br /&gt;
        mov edx, len        ; }&lt;br /&gt;
        int 80h             ; }&lt;br /&gt;
        mov eax, 1          ; Move 1 to eax&lt;br /&gt;
        add ebp, eax        ; Add eax to ebp (essentially increment ebp)&lt;br /&gt;
        mov eax, other      ; move other to eax&lt;br /&gt;
        mov ebx, data       ; move data to ebx&lt;br /&gt;
        cmp eax, ebx        ; compare them&lt;br /&gt;
        jne setup           ; If they are not the same, go back to the setup to increment other&lt;br /&gt;
&lt;br /&gt;
exit:                   ; Exits the program&lt;br /&gt;
        mov eax, 1          ; }&lt;br /&gt;
        mov ebx, 0          ; } System_exit call&lt;br /&gt;
        int 80h             ; }&lt;br /&gt;
&lt;br /&gt;
Expected output&lt;br /&gt;
&lt;br /&gt;
    Enter a number: 6&lt;br /&gt;
    0123456&lt;br /&gt;
&lt;br /&gt;
General Semantics of the program:&lt;br /&gt;
&lt;br /&gt;
    Display "Enter a number: "&lt;br /&gt;
    Read in an integer less than 32 bytes in size.&lt;br /&gt;
    Set a counter variable to the ASCII value of zero&lt;br /&gt;
    Loop:&lt;br /&gt;
    Display the character, adding 1 to it, and checking to see if it is   equal to the value    inputted.&lt;br /&gt;
    If it is equal, goto the exit section and exit&lt;br /&gt;
    Else loop.&lt;br /&gt;
&lt;br /&gt;
Why does it loop continuously? I have incremented the counter, and compared the input and the counter, so why doesn't it break?&lt;br /&gt;
&lt;br /&gt;
Thanks in advance&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pharabee/429798/429798/linux-nasm-assembly-prints-out-random-characters/</guid>
      <pubDate>Sat, 13 Oct 2012 01:23:08 -0700</pubDate>
      <category>Assembler Developer</category>
    </item>
  </channel>
</rss>