Write an assembly language program that corresponds to the following C++ program
ID: 3675134 • Letter: W
Question
Write an assembly language program that corresponds to the following C++ program. Comment each line except STOP & .END. Add something to the output that makes this program uniquely yours. Cut & paste the Assembler Listing into your document. (Hint: PEP/8 does not have a multiply instruction, however we have discussed an instruction that multiplies by 2. Please use that instruction.)
#include <iostream>
using namespace std;
int a;
int b;
int c;
int rslt;
int main( ) {
cout<<"Input 3 numbers " <<endl;
cin>>a>>b>>c;
rslt = (a + b + c) *2;
cout<<"a= " <<a <<endl;
cout<<"b= "<<b<<endl;
cout<<"c= "<<c<<endl;
cout<<endl;
cout<<"result= "<<rslt<<endl;
system("pause");//Not needed in Assembly Language
return 0;
}
Explanation / Answer
assembly language program that corresponds to the C++ program .Ltext0: .local _ZStL8__ioinit .comm _ZStL8__ioinit,1,1 .globl a .bss .align 4 a: 0000 00000000 .zero 4 .globl b .align 4 b: 0004 00000000 .zero 4 .globl c .align 4 c: 0008 00000000 .zero 4 .globl rslt .align 4 rslt: 000c 00000000 .zero 4 .section .rodata .LC0: 0000 496E7075 .string "Input 3 numbers " 74203320 6E756D62 65727320 00 .LC1: 0011 613D2000 .string "a= " .LC2: 0015 623D2000 .string "b= " .LC3: 0019 633D2000 .string "c= " .LC4: 001d 72657375 .string "result= " 6C743D20 00 .text .globl main main: .LFB971: .cfi_startproc 0000 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0001 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0004 53 pushq %rbx 0005 4883EC08 subq $8, %rsp .cfi_offset 3, -24 0009 BE000000 movl $.LC0, %esi 00 000e BF000000 movl $_ZSt4cout, %edi 00 0013 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 0018 BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 001d 4889C7 movq %rax, %rdi 0020 E8000000 call _ZNSolsEPFRSoS_E 00 0025 BE000000 movl $a, %esi 00 002a BF000000 movl $_ZSt3cin, %edi 00 002f E8000000 call _ZNSirsERi 00 0034 BE000000 movl $b, %esi 00 0039 4889C7 movq %rax, %rdi 003c E8000000 call _ZNSirsERi 00 0041 BE000000 movl $c, %esi 00 0046 4889C7 movq %rax, %rdi 0049 E8000000 call _ZNSirsERi 00 004e 8B150000 movl a(%rip), %edx 0000 0054 8B050000 movl b(%rip), %eax 0000 005a 01C2 addl %eax, %edx 005c 8B050000 movl c(%rip), %eax 0000 0062 01D0 addl %edx, %eax 0064 01C0 addl %eax, %eax 0066 89050000 movl %eax, rslt(%rip) 0000 006c 8B1D0000 movl a(%rip), %ebx 0000 0072 BE000000 movl $.LC1, %esi 00 0077 BF000000 movl $_ZSt4cout, %edi 00 007c E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 0081 89DE movl %ebx, %esi 0083 4889C7 movq %rax, %rdi 0086 E8000000 call _ZNSolsEi 00 008b BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 0090 4889C7 movq %rax, %rdi 0093 E8000000 call _ZNSolsEPFRSoS_E 00 0098 8B1D0000 movl b(%rip), %ebx 0000 009e BE000000 movl $.LC2, %esi 00 00a3 BF000000 movl $_ZSt4cout, %edi 00 00a8 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00ad 89DE movl %ebx, %esi 00af 4889C7 movq %rax, %rdi 00b2 E8000000 call _ZNSolsEi 00 00b7 BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 00bc 4889C7 movq %rax, %rdi 00bf E8000000 call _ZNSolsEPFRSoS_E 00 00c4 8B1D0000 movl c(%rip), %ebx 0000 00ca BE000000 movl $.LC3, %esi 00 00cf BF000000 movl $_ZSt4cout, %edi 00 00d4 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00d9 89DE movl %ebx, %esi 00db 4889C7 movq %rax, %rdi 00de E8000000 call _ZNSolsEi 00 00e3 BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 00e8 4889C7 movq %rax, %rdi 00eb E8000000 call _ZNSolsEPFRSoS_E 00 00f0 BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 00f5 BF000000 movl $_ZSt4cout, %edi 00 00fa E8000000 call _ZNSolsEPFRSoS_E 00 00ff 8B1D0000 movl rslt(%rip), %ebx 0000 0105 BE000000 movl $.LC4, %esi 00 010a BF000000 movl $_ZSt4cout, %edi 00 010f E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 0114 89DE movl %ebx, %esi 0116 4889C7 movq %rax, %rdi 0119 E8000000 call _ZNSolsEi 00 011e BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 0123 4889C7 movq %rax, %rdi 0126 E8000000 call _ZNSolsEPFRSoS_E 00 012b B8000000 movl $0, %eax 00 0130 4883C408 addq $8, %rsp 0134 5B popq %rbx 0135 5D popq %rbp .cfi_def_cfa 7, 8 0136 C3 ret .cfi_endproc .LFE971: _Z41__static_initialization_and_destruction_0ii: .LFB980: 0154 BF000000 movl $_ZStL8__ioinit, %edi 00 0159 E8000000 call _ZNSt8ios_base4InitC1Ev 00 015e BA000000 movl $__dso_handle, %edx 00 0163 BE000000 movl $_ZStL8__ioinit, %esi 00 0168 BF000000 movl $_ZNSt8ios_base4InitD1Ev, %edi 00 016d E8000000 call __cxa_atexit 00 .cfi_startproc 0137 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0138 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 013b 4883EC10 subq $16, %rsp 013f 897DFC movl %edi, -4(%rbp) 0142 8975F8 movl %esi, -8(%rbp) 0145 837DFC01 cmpl $1, -4(%rbp) 0149 7527 jne .L3 014b 817DF8FF cmpl $65535, -8(%rbp) FF0000 0152 751E jne .L3 .L3: 0172 C9 leave .cfi_def_cfa 7, 8 0173 C3 ret .cfi_endproc .LFE980: _GLOBAL__sub_I_a: .LFB981: .cfi_startproc 0174 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0175 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0178 BEFFFF00 movl $65535, %esi 00 017d BF010000 movl $1, %edi 00 0182 E8B0FFFF call _Z41__static_initialization_and_destruction_0ii FF 0187 5D popq %rbp .cfi_def_cfa 7, 8 0188 C3 ret .cfi_endproc .LFE981: .section .init_array,"aw" .align 8 0000 00000000 .quad _GLOBAL__sub_I_a 00000000 .text .Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.