Assembly loop and incrementation
<p>I have this assembly assignment I need to write and the task we need to do is accept user input and loop through each character and tally the number of alphabetic, numeric, and miscellaneous characters.</p>

<p>I found the easiest way to do this is to do three separate loops, one for counting the numbers, one for uppercase letter, and one for lowercase letter, than find the miscellaneous count by subtracting the numeric and alphabetic counts from the input string length.</p>

<p>I defined my alphabetic and numeric count variables to <code>0</code> in the <code>.data</code> section like this:</p>

<pre><code>acount: db 0                  ; alphabetic count variable
ncount: db 0                  ; numeric count variable
</code></pre>

<p>So that I could increment them. All of my loops are set up the same way so here is my numeric counter as an example:</p>

<pre><code>init_numeric:
        ;; Initialize the input for scanning
        mov     ecx, [rlen]             ; initialize the input length
        mov     esi, input              ; point to the start of input

scan_numeric:
        ;; beginning of the character scan for numeric values
        mov     al, [esi]               ; get a character
        inc     esi                     ; update to the next character
        cmp     al, '0'                 ; check the lower bound
        jb      not_num                 ; jump if below '0'
        cmp     al, '9'                 ; check the upper bound
        ja      not_num                 ; jump if above '9'
        inc     [ncount]                ; add 1 to the numeric count

not_num:
        dec     ecx                     ; update the number of characters
        jnz     scan_numeric            ; loop to top if more characters
</code></pre>

<p>Once these loops are complete, I'm getting the miscellaneous count, which is defined in the <code>.bss</code> section as:</p>

<pre><code>mcount: resb 4            ; reserve space for misc character count
</code></pre>

<p>And the calculation and operations to find in as such:</p>

<pre><code>get_misc:
        ;; Subtract the alphabetic and numeric counts from the length for
        ;; miscellanious character count
        mov     eax, [rlen]             ; move the input string length
        sub     eax, [acount]           ; subtract the alpha count
        sub     eax, [ncount]           ; subtract the numeric count
        mov     [mcount], eax           ; move eax value to mcount reserve
</code></pre>

<p>The problem is that when I run it, I get the user input perfectly fine but I get operation size undefined errors for the <code>inc</code> instructions, but when I do define them with <code>dword</code> or <code>word</code>, I get segfaults.</p>

<p>Any help please??</p>

<hr>

<p>EDIT:</p>

<p>Here is my section for the output prompts and values:</p>

<pre><code>result_write:
        ;; Write the results to the terminal

        ;; Alphabetic Count
        mov     eax, SYSCALL_WRITE      ; write function
        mov     ebx, STDOUT             ; file descripter
        mov     ecx, init               ; initial response msg
        mov     edx, ilen               ; initial msg length
        int     080h                    ; kernel execution

        mov     eax, SYSCALL_WRITE      ; write function
        mov     ebx, STDOUT             ; file descripter
        mov     ecx, [acount]           ; alphabetic count
        mov     edx, 4                  ; length
        int     080h                    ; kernel execution

        mov     eax, SYSCALL_WRITE      ; write function
        mov     ebx, STDOUT             ; file descripter
        mov     ecx, alpha              ; alphabetic response end
        mov     edx, alen               ; response length
        int     080h                    ; kernel execution
</code></pre>

<p>That is for the alphabetical count, the other two for numeric and misc. are identical.</p>