Translate the recursive program below into PEP/8 assembler. #include <iostream>
ID: 649431 • Letter: T
Question
Translate the recursive program below into PEP/8 assembler.
#include <iostream>
using namespace std;
int number;// variable for the input level for recursion
//this function computes par for the recursion level n
int par(int n) {
if (n>1) {
return 2 * par(n - 1);// if greater than 1 call function for n-1
}
else{
return 1;//if n=1 return 1
}
}
int main() {
cout << "Input level for recursion: ";//prompt for recursion level
cin >> number;
cout << "The Parade " << number << " has " << par(number) << " units" << endl;
//output // results for recursion level input
return 0;
}
Explanation / Answer
.Ltext0: .local _ZStL8__ioinit .comm _ZStL8__ioinit,1,1 .globl number .bss .align 4 number: 0000 00000000 .zero 4 .text .globl _Z3pari _Z3pari: .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 4883EC10 subq $16, %rsp 0008 897DFC movl %edi, -4(%rbp) 000b 837DFC01 cmpl $1, -4(%rbp) 000f 7E11 jle .L2 0011 8B45FC movl -4(%rbp), %eax 0014 83E801 subl $1, %eax 0017 89C7 movl %eax, %edi 0019 E8000000 call _Z3pari 00 001e 01C0 addl %eax, %eax 0020 EB05 jmp .L3 .L2: 0022 B8010000 movl $1, %eax 00 .L3: 0027 C9 leave .cfi_def_cfa 7, 8 0028 C3 ret .cfi_endproc .LFE971: .section .rodata .LC0: 0000 496E7075 .string "Input level for recursion: " 74206C65 76656C20 666F7220 72656375 .LC1: 001c 54686520 .string "The Parade " 50617261 64652000 .LC2: 0028 20686173 .string " has " 2000 .LC3: 002e 20756E69 .string " units" 747300 .text .globl main main: .LFB972: .cfi_startproc 0029 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 002a 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 002d 4154 pushq %r12 002f 53 pushq %rbx .cfi_offset 12, -24 .cfi_offset 3, -32 0030 BE000000 movl $.LC0, %esi 00 0035 BF000000 movl $_ZSt4cout, %edi 00 003a E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 003f BE000000 movl $number, %esi 00 0044 BF000000 movl $_ZSt3cin, %edi 00 0049 E8000000 call _ZNSirsERi 00 004e 8B050000 movl number(%rip), %eax 0000 0054 89C7 movl %eax, %edi 0056 E8000000 call _Z3pari 00 005b 89C3 movl %eax, %ebx 005d 448B2500 movl number(%rip), %r12d 000000 0064 BE000000 movl $.LC1, %esi 00 0069 BF000000 movl $_ZSt4cout, %edi 00 006e E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 0073 4489E6 movl %r12d, %esi 0076 4889C7 movq %rax, %rdi 0079 E8000000 call _ZNSolsEi 00 007e BE000000 movl $.LC2, %esi 00 0083 4889C7 movq %rax, %rdi 0086 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 008b 89DE movl %ebx, %esi 008d 4889C7 movq %rax, %rdi 0090 E8000000 call _ZNSolsEi 00 0095 BE000000 movl $.LC3, %esi 00 009a 4889C7 movq %rax, %rdi 009d E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00a2 BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 00a7 4889C7 movq %rax, %rdi 00aa E8000000 call _ZNSolsEPFRSoS_E 00 00af B8000000 movl $0, %eax 00 00b4 5B popq %rbx 00b5 415C popq %r12 00b7 5D popq %rbp .cfi_def_cfa 7, 8 00b8 C3 ret .cfi_endproc .LFE972: _Z41__static_initialization_and_destruction_0ii: .LFB981: 00d6 BF000000 movl $_ZStL8__ioinit, %edi 00 00db E8000000 call _ZNSt8ios_base4InitC1Ev 00 00e0 BA000000 movl $__dso_handle, %edx 00 00e5 BE000000 movl $_ZStL8__ioinit, %esi 00 00ea BF000000 movl $_ZNSt8ios_base4InitD1Ev, %edi 00 00ef E8000000 call __cxa_atexit 00 .cfi_startproc 00b9 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 00ba 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 00bd 4883EC10 subq $16, %rsp 00c1 897DFC movl %edi, -4(%rbp) 00c4 8975F8 movl %esi, -8(%rbp) 00c7 837DFC01 cmpl $1, -4(%rbp) 00cb 7527 jne .L6 00cd 817DF8FF cmpl $65535, -8(%rbp) FF0000 00d4 751E jne .L6 .L6: 00f4 C9 leave .cfi_def_cfa 7, 8 00f5 C3 ret .cfi_endproc .LFE981: _GLOBAL__sub_I_number: .LFB982: .cfi_startproc 00f6 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 00f7 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 00fa BEFFFF00 movl $65535, %esi 00 00ff BF010000 movl $1, %edi 00 0104 E8B0FFFF call _Z41__static_initialization_and_destruction_0ii FF 0109 5D popq %rbp .cfi_def_cfa 7, 8 010a C3 ret .cfi_endproc .LFE982: .section .init_array,"aw" .align 8 0000 00000000 .quad _GLOBAL__sub_I_number 00000000 .text .Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.