Question

In: Computer Science

The code must work on PEP/9, it shouldn't be too complicated and long Take the following...

The code must work on PEP/9, it shouldn't be too complicated and long

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;

}

Solutions

Expert Solution

Problem Stement :-

#include<iostream>

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;

}

Solution :-

.global main
.global _ZSt3cin
.global $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
.global _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
.global _ZNSt8ios_base4InitC1Ev
age:
.zero 4
first:
.zero 1
last:
.zero 1
.LC0:
.string "Your age "
.LC1:
.string "Initials "
.LC2:
.string "Cannot trust\n"
main:
pushq %rbp
movq %rsp, %rbp
movl $age, %esi
movl $_ZSt3cin, %edi
call _ZNSirsERi
movl $first, %esi
movl $_ZSt3cin, %edi
call _ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_
movl $last, %esi
movq %rax, %rdi
call _ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_
movl $.LC0, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movq %rax, %rdx
movl age(%rip), %eax
movl %eax, %esi
movq %rdx, %rdi
call _ZNSolsEi
movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi
movq %rax, %rdi
call _ZNSolsEPFRSoS_E
movl $.LC1, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movq %rax, %rdx
movzbl first(%rip), %eax
movsbl %al, %eax
movl %eax, %esi
movq %rdx, %rdi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c
movq %rax, %rdx
movzbl last(%rip), %eax
movsbl %al, %eax
movl %eax, %esi
movq %rdx, %rdi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c
movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi
movq %rax, %rdi
call _ZNSolsEPFRSoS_E
movl age(%rip), %eax
cmpl $29, %eax
jle .L2
movl $.LC2, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
.L2:
movl $0, %eax
popq %rbp
ret
_Z41__static_initialization_and_destruction_0ii:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L6
cmpl $65535, -8(%rbp)
jne .L6
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
.L6:
nop
leave
ret
_GLOBAL__sub_I_age:
pushq %rbp
movq %rsp, %rbp
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
ret


Related Solutions

Convert the following pep/9 machine language program into an assembly code. Determine the output of this...
Convert the following pep/9 machine language program into an assembly code. Determine the output of this program if the input is ‘tab’. The left column is the memory address of the first byte on the line: 0000 D1FC15 0003 F1001F 0006 D1FC15 0009 F10020 000C D1FC15 000F F10021 0012 D10020 0015 F1FC16 0018 D1001F 001B F1FC16 001E 00
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 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 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++)...
Please write a pep/9 assembly code that checks if a word or number is a palindrome
Please write a pep/9 assembly code that checks if a word or number is a palindrome
1) Translate the following C program to Pep/9 assembly language. Please attach screenshot of Pep/9 simulator...
1) Translate the following C program to Pep/9 assembly language. Please attach screenshot of Pep/9 simulator running the program. #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; }
Take the following code and modify the if(args >= 3) statement to work with a dynamic...
Take the following code and modify the if(args >= 3) statement to work with a dynamic amount of inputs. Example: ./cat file1 file2 file3 file4 filen-1 filen should output a text file that concatenates the files file1 to filen into one file #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) {    char ch;    if (argc ==1)    {        while((ch = fgetc(stdin)) != EOF) fputc(ch, stdout);    }    if (argc == 2)    {   ...
Please critically comment on the following sentence “Weighted Average Cost of Capital (WACC) is too complicated...
Please critically comment on the following sentence “Weighted Average Cost of Capital (WACC) is too complicated and not useful for financial management as we should only calculate the cost of borrowing/debt since we do not have to pay our shareholders any dividends if we choose to.” 
 According to a Chief Financial Officer of a listed company, she thinks that financial leverage is more effective than operating leverage in the real world as one can use financial derivatives to manage the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT