0

I am trying to convert the following C++ code into Pep/8 Assembly but it doesn't seem to work, and I really do not know whether it's because of my addressing modes or if there's a larger problem.

Here is an example which utilizes a switch statement, just not inside of a loop - Codepad Link. I also believe that I am having trouble making it so that the value in letter,s is compared to a case value. The book does not touch on switches much so it's really just trial and error at this point.

C++

int main() {

    char letter;
    int countA = 0,
    countB = 0,
    countC = 0;

    cin >> letter;

    do {
        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
    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 do
    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
Kenneth
  • 19
  • 7

0 Answers0