c++ - Pep/8 Assembly - Switch statement inside of loop -
i trying convert following c++ code pep/8 assembly doesn't seem work, , not know whether it's because of addressing modes or if there's larger problem.
here example utilizes switch statement, not inside of loop - codepad link. believe having trouble making value in letter,s compared case value. book not touch on switches it's trial , error @ point.
c++
int main() { char letter; int counta = 0, countb = 0, countc = 0; cin >> letter; { switch (letter) { case 'a' : counta++; break; case 'b' : countb++; break; case 'c' : countc++; break; } cin >> letter; } while (letter != 'x'); cout << "number of a's " << counta << endl << "number of b's " << countb << endl << "number of c's " << countc << endl; return 0; }
pep/8
br main main: subsp 1,i lda 0,i sta counta,d lda 0,i sta countb,d lda 0,i sta countc,d chari letter,s ; cin >> letter ldx letter,s aslx br do: br cases,x cases: .addrss casea .addrss caseb .addrss casec casea: lda counta,s ; counta++ adda 1,i sta counta,s br endcase ; break caseb: lda countb,s ; countb++ adda 1,i sta countb,s br endcase ;break casec: lda countc,s ; countc++ adda 1,i sta countc,s br endcase ; break endcase: chari letter,s ; } cin >> letter; } while... addsp 1,i while: ldbytea letter,d ; while (letter != 'x') cpa 'x',d brne endloop: stro msga,d ; cout << "number of a's: " << counta << endl deco counta,s charo '\n',i stro msgb,d ; cout << "number of b's: " << countb << endl deco countb,s charo '\n',i stro msgc,d ; cout << "number of c's: " << countc << endl deco countc,s charo '\n',i stop msga: .ascii "number of a's: \x00" msgb: .ascii "number of b's: \x00" msgc: .ascii "number of c's: \x00" .end
Comments
Post a Comment