I am taking a class that has us using pep9 for assembly. Here is my code:
BR main
number: .EQUATE 0 ;local variable
limit: .EQUATE 10 ;Constant
;
main: SUBSP 2,i ;push number
STRO msg,d ;printf("Enter a positive integer to Joshua's program:\x00")
DECI number,s ;scanf("%d", &number)
while: LDWA number,s
CPWA limit,i ;while
BRGT endwh
ADDA 1,i
STWA number,s
DECO number,s
STRO msg2,d
BR while
endwh: STRO msg3,d
ADDSP 2,i ;pop #number
STOP
msg: .ASCII "Enter a positive integer to Joshua's program:\x00"
msg3: .ASCII "\n\x00"
msg2: .ASCII " \x00"
.END
The code I am trying to mimic is as follows:
const int limit = 10;
int main() {
int number; // local variable
printf("Enter a positive integer to SOMEBODY's program: ");
//Replace SOMEBODY with your last name!
scanf("%d", &number);
while (number < limit)
{
number++;
printf("%d ", number);
}
printf("%c", '\n');
return 0;
}
The output I am getting is as follows:
Enter a positive integer to Joshua's program: 5 6 7 8 9 10 11
I am happy with everything but I believe it shouldn't be showing the '11' in the output. Am I missing something or is it working? I feel like it goes into the while loop one last time because 10 is not larger than 10 but anytime I run the C++ it does not include the '11' in the output. I assume something is wrong with my loop.