0

I have a code that I've been testing in Pep/8 Assembly, that takes an input of a character ><= and does comparisons. Once the comparisons are complete and the appropriate mathematical operation is done, I want to have the program prompt the user for another input.

I don't know why but my program is steamrolling over the input and because if it finds a 'invalid' input it just heads straight to the condition to exit the program. I am assuming it is a carriage return issue at this point. Is there any way to clear the contents of the 'guess' before prompting again?

     CHARI     guess,d     ;character input
     LDBYTEA   guess,d     ; load character into reg a
     CPA       '>',i
     BRNE      L

Any assistance would be helpful, thank you.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • Maybe just CPA for CR, and loop back to CHARI? (to create "input any non-CR character" infinite loop). (can't find any good resource for pep/8 online, so just guessing) – Ped7g Oct 21 '16 at 12:50

1 Answers1

0

There are a few problems you could be running into.

If your first number is greater than 255, you could run into issues with LDBYTEA, since it only replaces the last 8 bits of the register. This is easy to see with a quick test program.

 LDA      0x0123,i
 LDBYTEA  0x01,i
 STOP
 .END

(Ends with the accumulator having a value of 0x0101)

CPA would check all 16 bits of the register, which would cause it not to match > < or = if the first 8 bits aren't set to 0. You can solve this by loading a 0 before you load the byte, or by doing an AND with 0x00FF (255) to clear the first 8 bits.


When the user presses enter, that counts as a character that you will have to deal with. Your best option to ignore it is to check if the incoming character is "\n" (0x0A) and if so, branch back to the character input.

guess:   .BYTE   0
main:    CHARI   guess,d
         LDBYTEA guess,d
         CPA     '\n',i
         BREQ    main
         STOP
         .END

If you have to clear the contents of guess, you can do it by loading a value such as 0 into a register, and then saving it over guess.

 LDA     0,i
 STA     guess,d

If you have something in your accumulator that you don't want to overwrite, you can use the index register. (LDX and STX)

You could, of course, do another character input, which would overwrite the contents of guess.


If you continue to have issues, use the "Start Debugging Source" option to go through step by step. (Looks like a green arrow with a little beetle at the bottom)

CrazyMLC
  • 13
  • 4