Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Translate the following C++ program to assembly. #include <iostream> using names

ID: 3556491 • Letter: T

Question

Translate the following C++ program to assembly.

#include <iostream>
using namespace std;

int main(){
    int guess;
    cout << "Pick a number 0..3: ";
    cin >> guess;
    switch (guess){
        case 0:
        case 1:
            cout << "Too low";      // Two case statements execute the same code
            break;
        case 2:
            cout << "Right on";
            break;
        case 3:
            cout << "Too high";
            break;
        default:
            cout << "Illegal input";      // A default case has been added
    }
    cout << endl;
    return 0;
}

Explanation / Answer

0000 040003 BR main
;
;******* main ()
guess: .EQUATE 0 ;local variable #2d
0003 680002 main: SUBSP 2,i ;allocate #guess
0006 410037 STRO msgIn,d ;cout << "Pick a number 0..3: "
0009 330000 DECI guess,s ;cin >> Guess
000C CB0000 LDX guess,s ;switch (Guess)
000F 1D ASLX ;addresses occupy two bytes
0010 050013 BR guessJT,x
0013 001B guessJT: .ADDRSS case0
0015 0021 .ADDRSS case1
0017 0027 .ADDRSS case2
0019 002D .ADDRSS case3
001B 41004C case0: STRO msg0,d ;cout << "Not close"
001E 040030 BR endCase ;break
0021 410056 case1: STRO msg1,d ;cout << "Close"
0024 040030 BR endCase ;break
0027 41005C case2: STRO msg2,d ;cout << "Right on"
002A 040030 BR endCase ;break
002D 410065 case3: STRO msg3,d ;cout << "Too high"
0030 50000A endCase: CHARO ' ',i ;count << endl
0033 600002 ADDSP 2,i ;deallocate #guess
0036 00 STOP

0037 506963 msgIn: .ASCII "Pick a number 0..3: "
...
004C 4E6F74 msg0: .ASCII "Not close"
...
0056 436C6F msg1: .ASCII "Close"
...
005C 526967 msg2: .ASCII "Right on"
...
0065 546F6F msg3: .ASCII "Too high"
...
006E .END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote