0

我正在尝试将以下 C++ 代码转换为 Pep/8 程序集,但它似乎不起作用,我真的不知道这是因为我的寻址模式还是存在更大的问题。

这是一个使用 switch 语句的示例,只是不在循环内部 - Codepad Link。我也相信我很难将字母中的值与大小写值进行比较。这本书没有过多地涉及开关,所以在这一点上实际上只是反复试验。

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;

}

鼓舞士气/ 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
4

0 回答 0