assembly - Pep8 - Base 2 to Base 10 converter -


i developing called simple pep8 program, converts base 2 number base 10.

below requirements:

  1. ask user input in base 2
  2. convert base 2 value decimal , output that.
  3. finally loop , ask user if want enter value. if ask question again, else display message 'done' (or effect)

so far trying read character , store string.

could 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 string work, on complicates problem.

you might have found out during month between question , answer, can build number read each character, using arithmetic shift left operation.

        br  main            ;#include <iostream> letter: .byte   0           ;char letter = 0; number: .word   0           ;int number = 0;                             ;int main() { main:   chari   letter,d    ;   std::cin >> letter;         lda     0,i         ldbytea letter,d         cpa     '0',i       ;   if (letter == '0') {         brne    notzer         lda     number,d         asla                ;       number *= 2;         sta     number,d         br      main        ;       main(); notzer: cpa     '1',i       ;   } else if (letter == '1') {         brne    end         lda     number,d         asla                ;       number *= 2;         adda    1,i         ;       number++;                sta     number,d         br      main        ;       main();                             ;   } else { end:    deco    number,d    ;       std::cout << number;         stop                ;       return 0;         .end                ;   }                             ;} 

this isn't simplest or best way solve problem though, trying make easy understand.

for example, keep number in index register until ready print it, saving lines/time loading , storing accumulator. (you use aslx , addx 1,i)


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -