In: Computer Science
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;
}
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