0

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.

  • The reverse of `<` is `>=` but you used `BRGT` which is `>` so you enter into the loop even when `number == limit`. Change to `BRGE`. PS: next time use your simulator to single step the code. – Jester Nov 22 '21 at 01:00
  • Where is this simulator that you speak of? Sounds very helpful. – JoshuaRHitchcock Nov 22 '21 at 01:16
  • 1
    Most toy architectures have a simulator with a built-in debugger that lets you single step. And yes, it's basically essential for debugging, not using one is a big waste of your own and other people's time. Google finds multiple hits for "pep9 simulator" https://computersystemsbook.com/5th-edition/pep9/ / https://github.com/StanWarford/pep9suite among others. – Peter Cordes Nov 22 '21 at 01:31
  • PEP-8 & 9 are, as Peter says, toy or educational processors, there is no real hardware for them. Therefore, if you are running programs for them you already have a simulator, just need to consult its docs for how to run its debugger. – Erik Eidt Nov 22 '21 at 16:49

0 Answers0