I want to write an assembly program that continually takes an integer input from the user until a total of 10 inputs have been reached or the user enters a 0. At the end the program will display the count for number of positive and negative integers. So far I have this code:

INCLUDE irvine32.inc

numneg DWORD 0
numpos DWORD 0
string BYTE "Enter an integer (0 to quit): "

main PROC
mov edx, OFFSET string
call WriteString
call ReadInt
cmp eax, 0
jl addneg

add numneg, 1
mov eax, numneg
call WriteInt

main ENDP
END main

Right now I'm only testing it with one input, but the jump doesn't seem to work. It's only supposed to jump if the number entered is negative, but now it jumps for everything. And if I write something else immediately after the "jl addneg" it will execute that too. What am I doing wrong here? Thanks.
Posted on 2008-11-16 05:16:06 by goldeneye
Instead of comparing with zero, just test bit 31 of eax.
Negative numbers will have the highest bit set.
Posted on 2008-11-16 05:29:51 by Homer
What am I doing wrong here?

As your code is written, you don't inform the computer to skip the "addneg" section if your number is not negative. It simply keeps on performing all the instructions until it exits.
Posted on 2008-11-16 20:22:18 by Raymond

test eax, eax

is better than cmp eax,0...
Posted on 2008-11-25 15:14:31 by GermainR27