+1 (315) 557-6473 

Convert Simple C++ Program in Pep9 Assembly Assignment Solution.


Instructions

Objective
Write a C++ assignment that requires students to create a program to convert a simple C++ program into Pep9 assembly. This assignment will help students gain a deeper understanding of both C++ programming and assembly language, while also enhancing their problem-solving skills and knowledge of low-level programming concepts. By completing this assignment, students will have the opportunity to bridge the gap between high-level programming and the intricacies of assembly language, thereby honing their coding abilities across multiple domains.

Requirements and Specifications

Take the following C++ program and translate it into PEP/9 assembly language.
#include
using namespace std;
int num;
char letter;
int main() {
   cin >> num;
   cin >> letter;
   cout << "You inputted " << num << endl;
   cout << "Option " << letter << endl;
   if (letter == '*')
      cout << "Multiplied by 2 " << num*2 << endl;
   return 0;
}
Screenshots of output
Convert simple C++ program in Pep9 assembly

Source Code

; int main()

temp: .EQUATE 0 ; temporary variable #2d

main: DECI num,d ; cin >> num;

         LDBA charIn,d ; cin >> letter

         STBA letter,d

         STRO msg1,d ; cout << "You inputted " << num << endl;

         DECO num,d

         LDBA '\n',i

         STBA charOut,d

         STRO msg2,d ; cout << "Option " << letter << endl;

         LDBA letter,d

         STBA charOut,d

         LDBA '\n',i

         STBA charOut,d

         LDBA letter,d

if: CPBA '*',i ; if (letter == '*')

         BRNE endif

         LDWA num,d ; //calculate num+num to get 2*num

         ADDA num,d

         SUBSP 2,i ; //push #temp

         STWA temp,s

         STRO msg3,d ; cout << "Multiplied by 2 " << num*2 << endl;

         DECO temp,s

         ADDSP 2,i ; //pop #temp

         LDBA '\n',i

         STBA charOut,d

endif: STOP ; return 0;

num: .WORD 0 ; int num

letter: .BYTE 0 ; char letter

msg1: .ASCII "You inputted \x00"

msg2: .ASCII "Option \x00"

msg3: .ASCII "Multiplied by 2 \x00"

         .END