Question: This is assembly language code. I deleted all the assembler directives. Please describe the result of each instruction in the code below please. main: pushq

This is assembly language code. I deleted all the assembler directives. Please describe the result of each instruction in the code below please.

main:

pushq %rbp

movq %rsp, %rbp

subq $16, %rsp

movl $5, -12(%rbp)

movl $3, -8(%rbp)

movl -12(%rbp), %edx

movl -8(%rbp), %eax

addl %edx, %eax

movl %eax, %edx

shrl $31, %edx

addl %edx, %eax

sarl %eax

movl %eax, -4(%rbp)

leaq .LC0(%rip), %rsi

leaq _ZSt4cout(%rip), %rdi

call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT

movq %rax, %rdx

movl -4(%rbp), %eax

movl %eax, %esi

movq %rdx, %rdi

call _ZNSolsEi@PLT

movq %rax, %rdx

movq _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rax

movq %rax, %rsi

movq %rdx, %rdi

call _ZNSolsEPFRSoS_E@PLT

movl $0, %eax

leave

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 .L5

cmpl $65535, -8(%rbp)

jne .L5

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

nop

leave

ret

_GLOBAL__sub_I_main:

pushq %rbp

movq %rsp, %rbp

movl $65535, %esi

movl $1, %edi

call _Z41__static_initialization_and_destruction_0ii

popq %rbp

ret

the c++ code that this assembly language was generated by is listed below:

#include

#define Y 3

int main()

{

int x = 5;

int y = Y;

int ave = (x + y) / 2;

std::cout << "Average is " << ave << std::endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!