Matt
Matt

Reputation: 15

cant figure out what is wrong with code

I am supposed to display the numbers 1 through 20 but I can not figure out what's wrong. At the beginning it is going correct but it is going to 21 instead of 20.

INCLUDE Irvine32.inc
TITLE 1through20
.data
.code

main proc

sub eax, eax
mov eax, 1
call writeDec
call crlf
mov ecx, 20

L1:
add eax, 1
call writeDec
call crlf
loop L1
exit

main EndP

END main

Upvotes: 2

Views: 61

Answers (1)

Fifoernik
Fifoernik

Reputation: 9899

You're doing a separate display of the first number followed by a loop that displays 20 numbers. So in total you display 21 numbers which is 1 too many!
Simply drop 3 lines from your program (keep the sub eax, eax in this solution):

sub eax, eax
;;;;;;;;;;;;;;;;mov eax, 1
;;;;;;;;;;;;;;;;call writeDec
;;;;;;;;;;;;;;;;call crlf
mov ecx, 20

L1:
add eax, 1
call writeDec
call crlf
loop L1

Upvotes: 1

Related Questions