2

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
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Matt
  • 13
  • 4

1 Answers1

1

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
Fifoernik
  • 9,779
  • 1
  • 21
  • 27