This is my first assessed program in assembly language. I have been working with Visual Studio’s Visual C++ Win32 Console Application and using (_asm) assembly code. Here is what I had to do:

Requirements: Write a program in assembly language which takes an integer input, n, and then reads in that number, n, of values. It will have three counters: pcount, zcount, and ncount which are incremented by 1 when the value read in is positive (>0), zero (=0), or negative (<0) respectively. At the end of the list of numbers, these counter values will be written out.

I didn’t have too much trouble writing the code, once I got my head around what needed to be on the stack, when, it was quite a repetitive task (lots of printf and scanf situations). However, once I began to test my program I ran into some errors…

  1. The first error I found was when I set n = 0. Obviously this meant that when the loop decremented the ECX counter it went to -1 and so it never Reached Zero- the condition for the loop ending.
    • I inserted a jump to the end of the loop body if the input was less than or equal to zero, which solved the issue.
  2. The second error I encountered was when testing the result of entering invalid input. I wanted to check what happened if the user wrote ‘bob’ instead of a numerical value. (For my Java assignments, the specifications have always stated that we can assume that the user will not enter invalid input. As I didn’t see that in this spec., I decided to test it.) What appearred to have happened was that the value wasn’t positive, so when compared to zero it didn’t jg (jump if greater than) to the posroutine, or jl (jump if less than) to the negroutine, but continued to what I’d left as the default, incrementing zcount.
    • To solve this, I inserted a zero routine to make each type of value have a condition and the default be to jump to the end of the loop body without incrementing any counters.
  3. However, I tested it again and got the same result. I then realised that, due to the variable ‘value’ being initialised as equal to zero in the supporting C++ at the beginning of the code, perhaps the zero counter is incremented when the inputted value is invalid.
    • As this is the first assignment I’ve had in assembly, I haven’t had much experience of it. I don’t really know how to approach this issue. I tried not assigning a value to ‘value’ in the C++ but when I placed a watch on it while debugging, I noticed that the default value assigned to it is -858993460, which then increases the ncount instead of the zcount, which isn’t any better.

Obviously, I’m all for thorough testing but when I highlight an error which I don’t know how to fix, I wonder whether it would have been better to lose marks for weak testing than to point out the downfalls in my program without solving them…

Leave a Reply

Your email address will not be published. Required fields are marked *