Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(pep8 Assembly language program) specify a structure called Fraction with num an

ID: 3771539 • Letter: #

Question

(pep8 Assembly language program)

specify a structure called Fraction with num and denom as its integer members. Keep asking the user if he or she wants to add a fraction. If the answer is 'y' or 'Y', allocate memory dynamically for a Fraction structure, read a fraction and store the pointer returned by new in a locally defined array of integers of maximum size 10.

Then, read a Fraction, storing it in a Fraction variable local to main and search for it in the above array of pointers. Print the index where it was found or "Not found" otherwise.

The following shows a sample execution of the program:

Input: 2 / 3 1 / 2 1 / 4 1 / 3 2 / 5 -99

Enter fraction to search for: 1/3

1/3 was found at index 3.

Explanation / Answer

.section .text._ZnwmPv,"axG",@progbits,_ZnwmPv,comdat .weak _ZnwmPv _ZnwmPv: .LFB281: .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 48897DF8 movq %rdi, -8(%rbp) 0008 488975F0 movq %rsi, -16(%rbp) 000c 488B45F0 movq -16(%rbp), %rax 0010 5D popq %rbp .cfi_def_cfa 7, 8 0011 C3 ret .cfi_endproc .LFE281: .local _ZStL8__ioinit .comm _ZStL8__ioinit,1,1 .section .text._ZN8fractionC2Eii,"axG",@progbits,_ZN8fractionC5Eii,comdat .align 2 .weak _ZN8fractionC2Eii _ZN8fractionC2Eii: .LFB3537: .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 48897DF8 movq %rdi, -8(%rbp) 0008 8975F4 movl %esi, -12(%rbp) 000b 8955F0 movl %edx, -16(%rbp) .LBB2: 000e 488B45F8 movq -8(%rbp), %rax 0012 8B55F4 movl -12(%rbp), %edx 0015 8910 movl %edx, (%rax) 0017 488B45F8 movq -8(%rbp), %rax 001b 8B55F0 movl -16(%rbp), %edx 001e 895004 movl %edx, 4(%rax) .LBE2: 0021 5D popq %rbp .cfi_def_cfa 7, 8 0022 C3 ret .cfi_endproc .LFE3537: .weak _ZN8fractionC1Eii .set _ZN8fractionC1Eii,_ZN8fractionC2Eii .section .rodata .align 8 .LC0: 0000 446F2079 .string "Do you want to add a fraction " 6F752077 616E7420 746F2061 64642061 001f 00 .align 8 .LC1: 0020 456E7465 .string "Enter Numerator and Denomiantor " 72204E75 6D657261 746F7220 616E6420 0041 00000000 .align 8 000000 .LC2: 0048 456E7465 .string "Enter fraction to search for " 72206672 61637469 6F6E2074 6F207365 .text .globl main main: .LFB3539: .cfi_startproc .cfi_personality 0x3,__gxx_personality_v0 .cfi_lsda 0x3,.LLSDA3539 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 4883EC48 subq $72, %rsp .cfi_offset 3, -24 .LBB3: 0009 488D45D0 leaq -48(%rbp), %rax 000d 4889C7 movq %rax, %rdi .LEHB0: 0010 E8000000 call _ZNSt6vectorIP8fractionSaIS1_EEC1Ev 00 .LEHE0: .L8: .LBB4: 0015 BE000000 movl $.LC0, %esi 00 001a BF000000 movl $_ZSt4cout, %edi 00 .LEHB1: 001f E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 0024 488D45BB leaq -69(%rbp), %rax 0028 4889C6 movq %rax, %rsi 002b BF000000 movl $_ZSt3cin, %edi 00 0030 E8000000 call _ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_ 00 .LBB5: 0035 0FB645BB movzbl -69(%rbp), %eax 0039 3C79 cmpb $121, %al 003b 7572 jne .L5 .LBB6: 003d BE000000 movl $.LC1, %esi 00 0042 BF000000 movl $_ZSt4cout, %edi 00 0047 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 004c BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 0051 4889C7 movq %rax, %rdi 0054 E8000000 call _ZNSolsEPFRSoS_E 00 0059 488D45BC leaq -68(%rbp), %rax 005d 4889C6 movq %rax, %rsi 0060 BF000000 movl $_ZSt3cin, %edi 00 0065 E8000000 call _ZNSirsERi 00 006a 488D55C0 leaq -64(%rbp), %rdx 006e 4889D6 movq %rdx, %rsi 0071 4889C7 movq %rax, %rdi 0074 E8000000 call _ZNSirsERi 00 0079 BF080000 movl $8, %edi 00 007e E8000000 call _Znwm 00 0083 4889C3 movq %rax, %rbx 0086 8B55C0 movl -64(%rbp), %edx 0089 8B45BC movl -68(%rbp), %eax 008c 89C6 movl %eax, %esi 008e 4889DF movq %rbx, %rdi 0091 E8000000 call _ZN8fractionC1Eii 00 0096 48895DC8 movq %rbx, -56(%rbp) 009a 488D55C8 leaq -56(%rbp), %rdx 009e 488D45D0 leaq -48(%rbp), %rax 00a2 4889D6 movq %rdx, %rsi 00a5 4889C7 movq %rax, %rdi 00a8 E8000000 call _ZNSt6vectorIP8fractionSaIS1_EE9push_backERKS1_ 00 .LBE6: 00ad EB12 jmp .L18 .L5: 00af 90 nop .LBE5: .LBE4: 00b0 BE000000 movl $.LC2, %esi 00 00b5 BF000000 movl $_ZSt4cout, %edi 00 00ba E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00bf EB05 jmp .L19 .L18: 00c1 E94FFFFF jmp .L8 FF .L19: 00c6 488D45C0 leaq -64(%rbp), %rax 00ca 4889C6 movq %rax, %rsi 00cd BF000000 movl $_ZSt3cin, %edi 00 00d2 E8000000 call _ZNSirsERi 00 00d7 488D55C8 leaq -56(%rbp), %rdx 00db 4889D6 movq %rdx, %rsi 00de 4889C7 movq %rax, %rdi 00e1 E8000000 call _ZNSirsERi 00 .LBB7: 00e6 C745C400 movl $0, -60(%rbp) 000000 00ed EB75 jmp .L9 .L14: 00ef 8B45C4 movl -60(%rbp), %eax 00f2 4863D0 movslq %eax, %rdx 00f5 488D45D0 leaq -48(%rbp), %rax 00f9 4889D6 movq %rdx, %rsi 00fc 4889C7 movq %rax, %rdi 00ff E8000000 call _ZNSt6vectorIP8fractionSaIS1_EEixEm 00 0104 488B00 movq (%rax), %rax 0107 8B10 movl (%rax), %edx 0109 8B45C0 movl -64(%rbp), %eax 010c 39C2 cmpl %eax, %edx 010e 7529 jne .L10 0110 8B45C4 movl -60(%rbp), %eax 0113 4863D0 movslq %eax, %rdx 0116 488D45D0 leaq -48(%rbp), %rax 011a 4889D6 movq %rdx, %rsi 011d 4889C7 movq %rax, %rdi 0120 E8000000 call _ZNSt6vectorIP8fractionSaIS1_EEixEm 00 0125 488B00 movq (%rax), %rax 0128 8B5004 movl 4(%rax), %edx 012b 8B45C8 movl -56(%rbp), %eax 012e 39C2 cmpl %eax, %edx 0130 7507 jne .L10 0132 B8010000 movl $1, %eax 00 0137 EB05 jmp .L11 .L10: 0139 B8000000 movl $0, %eax 00 .L11: 013e 84C0 testb %al, %al 0140 741E je .L12 0142 8B45C4 movl -60(%rbp), %eax 0145 89C6 movl %eax, %esi 0147 BF000000 movl $_ZSt4cout, %edi 00 014c E8000000 call _ZNSolsEi 00 0151 BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 0156 4889C7 movq %rax, %rdi 0159 E8000000 call _ZNSolsEPFRSoS_E 00 .LEHE1: 015e EB24 jmp .L13 .L12: 0160 8345C401 addl $1, -60(%rbp) .L9: 0164 8B45C4 movl -60(%rbp), %eax 0167 4863D8 movslq %eax, %rbx 016a 488D45D0 leaq -48(%rbp), %rax 016e 4889C7 movq %rax, %rdi 0171 E8000000 call _ZNKSt6vectorIP8fractionSaIS1_EE4sizeEv 00 0176 4839C3 cmpq %rax, %rbx 0179 0F92C0 setb %al 017c 84C0 testb %al, %al 017e 0F856BFF jne .L14