Question

In: Computer Science

Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace...

  1. Take the following C++ program and translate it into assembly language( pep9 )

#include

using namespace std;

char ch;

int main() {

   cin >> ch;

   cout << "You inputted " << ch << endl;

   ch++;

   cout << "Next character is " << ch << endl;

if (ch <= ‘Z’)

        cout << “Could be luppercase\n”;

   return 0;

}

Solutions

Expert Solution

Given program :

#include <iostream>
using namespace std;
char ch;
int main()
{
cin >> ch;
cout << "You inputted " << ch << endl;
ch++;
cout << "Next character is " << ch << endl;
if (ch <= 'Z')
cout << "Could be luppercase\n";
return 0;
}

Save tis program as program.cpp

In Assembly language

   .file   "program.cpp"
   .text
   .section   .rodata
   .type   _ZStL19piecewise_construct, @object
   .size   _ZStL19piecewise_construct, 1
_ZStL19piecewise_construct:
   .zero   1
   .local   _ZStL8__ioinit
   .comm   _ZStL8__ioinit,1,1
   .globl   ch
   .bss
   .type   ch, @object
   .size   ch, 1
ch:
   .zero   1
   .section   .rodata
.LC0:
   .string   "You inputted "
.LC1:
   .string   "Next character is "
.LC2:
   .string   "Could be luppercase\n"
   .text
   .globl   main
   .type   main, @function
main:
.LFB1522:
   .cfi_startproc
   endbr64
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   leaq   ch(%rip), %rsi
   leaq   _ZSt3cin(%rip), %rdi
   call   _ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_@PLT
   leaq   .LC0(%rip), %rsi
   leaq   _ZSt4cout(%rip), %rdi
   call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
   movq   %rax, %rdx
   movzbl   ch(%rip), %eax
   movsbl   %al, %eax
   movl   %eax, %esi
   movq   %rdx, %rdi
   call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c@PLT
   movq   %rax, %rdx
   movq   _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rax
   movq   %rax, %rsi
   movq   %rdx, %rdi
   call   _ZNSolsEPFRSoS_E@PLT
   movzbl   ch(%rip), %eax
   addl   $1, %eax
   movb   %al, ch(%rip)
   leaq   .LC1(%rip), %rsi
   leaq   _ZSt4cout(%rip), %rdi
   call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
   movq   %rax, %rdx
   movzbl   ch(%rip), %eax
   movsbl   %al, %eax
   movl   %eax, %esi
   movq   %rdx, %rdi
   call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c@PLT
   movq   %rax, %rdx
   movq   _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rax
   movq   %rax, %rsi
   movq   %rdx, %rdi
   call   _ZNSolsEPFRSoS_E@PLT
   movzbl   ch(%rip), %eax
   cmpb   $90, %al
   jg   .L2
   leaq   .LC2(%rip), %rsi
   leaq   _ZSt4cout(%rip), %rdi
   call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L2:
   movl   $0, %eax
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1522:
   .size   main, .-main
   .type   _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
.LFB2012:
   .cfi_startproc
   endbr64
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $16, %rsp
   movl   %edi, -4(%rbp)
   movl   %esi, -8(%rbp)
   cmpl   $1, -4(%rbp)
   jne   .L6
   cmpl   $65535, -8(%rbp)
   jne   .L6
   leaq   _ZStL8__ioinit(%rip), %rdi
   call   _ZNSt8ios_base4InitC1Ev@PLT
   leaq   __dso_handle(%rip), %rdx
   leaq   _ZStL8__ioinit(%rip), %rsi
   movq   _ZNSt8ios_base4InitD1Ev@GOTPCREL(%rip), %rax
   movq   %rax, %rdi
   call   __cxa_atexit@PLT
.L6:
   nop
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE2012:
   .size   _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii
   .type   _GLOBAL__sub_I_ch, @function
_GLOBAL__sub_I_ch:
.LFB2013:
   .cfi_startproc
   endbr64
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movl   $65535, %esi
   movl   $1, %edi
   call   _Z41__static_initialization_and_destruction_0ii
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE2013:
   .size   _GLOBAL__sub_I_ch, .-_GLOBAL__sub_I_ch
   .section   .init_array,"aw"
   .align 8
   .quad   _GLOBAL__sub_I_ch
   .hidden   __dso_handle
   .ident   "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
   .section   .note.GNU-stack,"",@progbits
   .section   .note.gnu.property,"a"
   .align 8
   .long   1f - 0f
   .long   4f - 1f
   .long   5
0:
   .string   "GNU"
1:
   .align 8
   .long   0xc0000002
   .long   3f - 2f
2:
   .long   0x3
3:
   .align 8
4:

Please give like and comment

THANKS !!!!!!!!!!!!!!


Related Solutions

Take the following C++ program and translate it into Pep/9 assembly language #include using namespace std;...
Take the following C++ program and translate it into Pep/9 assembly language #include using namespace std; int age; char first, last; int main() {    cin >> age;    cin >> first >> last;    cout << "Your age " << age << endl;    cout << "Initials " << first << last << endl;    if (age >= 30)        cout << “Cannot trust\n”;    return 0; }
Take the following C++ program and translate it into PEP/9 assembly language #include <iostream> using namespace...
Take the following C++ program and translate it into PEP/9 assembly language #include <iostream> 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; }
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0) return 0; else if (n <= 2) return 1; else { temp = fib(n – 1); return temp + fib(n-2); } } int main() { int num; cout << "Which fibonacci number? "; cin >> num; cout << fib(num) << endl; return 0; } You must use equates to access the stack and follow the...
Take the following program from C++ and translate it into Pep/9 assembly language: #include <iostream> using...
Take the following program from C++ and translate it into Pep/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)...
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number;...
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number; Scanf (“%d”, & number); if (number % 2 ==0) { printf (“Even\n”); } else { printf(“Odd\n”); } Return 0; }
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum;...
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum; scanf("%d", &numitms); sum=0; for (j=1;j<=numitms;j++) { scanf("%d", &data); sum+=data; } printf("sum: %d\n",sum); return0; } I got an answer with an error. Please debug the answer or have a new correct answer (don't copy and paste others' answer) main: SUBSP 2,i DECI numItms,i DECI j,j DECI data,d DECI sum,s LDWA numItms,i sum: .EQUATE 0 LDWA 1,i STWA j,j for: CPWA numItms, j BRGE endFor STRO...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1;...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1; char ch2; int main() { cin.get(ch1); cin.get(ch2);    cout << ch1 << chConst << ch2;    return 0; }
Writing a squareroot program in C++ using only: #include <iostream> using namespace std; The program must...
Writing a squareroot program in C++ using only: #include <iostream> using namespace std; The program must be very basic. Please don't use math sqrt. Assume that the user does not input anything less than 0. For example: the integer square root of 16 is 4 because 4 squared is 16. The integer square root of 18 is 5 because 4 squared is 16 and 5 squared is 25, so 18 is bigger than 16 but less than 25.  
Writing an nth root program in C++ using only: #include using namespace std; The program must...
Writing an nth root program in C++ using only: #include using namespace std; The program must be very basic. Please don't use math sqrt or pow . For example, the 4th root of 16 is 2 because 2 * 2 * 2 * 2 = 16. The 4th root of 20 is 2 because 2 * 2 * 2 * 2 = 16 and 16 is less than 20, and 3 * 3 * 3 * 3 = 81, which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT