Quote:
Originally Posted by displaytor
What I'm trying to do is ask the user to input a number, then keep adding every number from the defined one until the counter reaches zero and finally print the sum on the screen. Also, I only want to use system calls (no C libs).
|
Are you asking for someone to write that program for you, or are you trying to learn how to do that yourself?
If the code you posted had been close to correct, I wouldn't need to ask that. But your code is far enough from correct that fixing it is nearly writing it from scratch.
I think you should give the problem more thought:
Your current input code:
Code:
;user input
mov eax,3 ; syscall: read
mov ebx,0 ; keyboard
mov ecx,choice ; offset
int 80h ; kernel call
Think about what an input operation is: A sequence of characters is read into a buffer. How long is the buffer? How does the syscall know how long the buffer is (to avoid giving you too much input)? How does the program know how much input it got (might be less than a full buffer)? Is the terminating newline character part of the text delivered to the buffer?
Once you have the input, what do you have? If the user pressed '1' then '0' then newline, what translates all that into the number ten that you seem to want?
Your processing code:
Code:
;arithmetic
calc:
add edx,ecx
dec ecx
jecxz result
What was in edx before that code was reached? What was in ecx before that code was reached? What happens after jecxz if ecx has reached zero? What happens if ecx hasn't reached zero?
The above issues are not nearly the only problems. Look at every section of your code that might not be working and ask yourself similar questions.