I am developing a so called simple pep8 program, that converts a base 2 number into base 10.
Below are the requirements:
- Ask for user input in base 2
- Convert the base 2 value into decimal and output that.
- Finally loop and ask user if they want to enter another value. If so ask question again, else display message 'done' (or something to that effect)
So far I am trying to read a character and store this as a string.
Could anyone help!
Thank you.
BR main
letter: .BLOCK 1 ;global variable #1c
;
main: CHARI letter,d ;cin >> letter
LDA 0x0000,i
while: LDBYTEA letter,d ;while (letter != '*')
CPA '*',i
BREQ endWh
CHARO letter,d ; cout << letter
CHARI letter,d ; cin >> letter
BR while
endWh: STOP
.END
Storing it as a string would work, but that over complicates the problem.
You might have found this out during the month between question and answer, but you can build the number up as you read each character, using the arithmetic shift left operation.
This isn't necessarily the simplest or best way to solve the problem though, I was just trying to make it easy to understand.
For example, you could keep the number in the index register until you were ready to print it, saving you lines/time from loading and storing it with the accumulator. (you could just use ASLX and ADDX 1,i)