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

Write an Assembly program using pep8 that reads an integer and then stores all F

ID: 3568175 • Letter: W

Question

Write an Assembly program using pep8 that reads an integer and then stores all Fibonacci numbers from 0 to the integer entered (including that) into an array of integers of maximum size 50. Once all numbers have been stored, print them and then read an integer and display it's index in the array if it's one of the series or print "Not in series", if not.  To search for the number, use binary search on the array elements.

The following is the C++ program for binary search:

int vector[50];

//populate array with Fibonacci numbers up to the limit

int first = 0, last = size - 1, mid = (first + last) / 2; where size is the number of integers stored in the array

while(first <= last)
{
        if(value < nums[mid]) //if value < middle value
        {
                last = mid - 1;
                mid = (first + last) / 2;
        }
       else if(value > nums[mid])
       {
                first = mid + 1;
                mid = (first + last) / 2;
       }
       else

       {
                cout << " Value found at index " << mid;

                //return

       }
}
cout << " Value is not part of the series.";

//return

Example:

Enter limit: 150

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 134

Enter number:   89

89 found at index 11.

Put your name on top as a comment and comment most if not all your statements. You can use C++ code for commenting your statements.

Explanation / Answer

C++ Program:

#include <iostream>

#include <string>

using namespace std;

int main()

{

int vector[50];

//populate array with Fibonacci numbers up to the limit

int size = 50;

int first = 0, last = size - 1, mid = (first + last) / 2;

vector[0] = 0;

vector[1] = 1;

int i = 1;

while((vector[i] + vector[i-1]) < size)

{

vector[i+1] = vector[i-1] + vector[i];

i++;

cout<<vector[i]<<" ";

}

int value = 8;

//where size is the number of integers stored in the array

while(first <= last)

{

        if(value < vector[mid]) //if value < middle value

        {

                last = mid - 1;

                mid = (first + last) / 2;

        }

       else if(value > vector[mid])

       {

                first = mid + 1;

                mid = (first + last) / 2;

       }

       else

       {

                cout << " Value found at index " << mid;

                //return

       }

}

cout << " Value is not part of the series.";

}

-----------------------------------------------------------------------------------------------------------------------------------

Machine Code:

             .Ltext0:
               .local _ZStL8__ioinit
               .comm _ZStL8__ioinit,1,1
               .section .rodata

             .LC0:
0000 0900       .string " "

             .LC1:
0002 0A56616C   .string " Value found at index "
     75652066
     6F756E64
     20617420
     696E6465
0019 00000000   .align 8
     000000

             .LC2:
0020 0A56616C   .string " Value is not part of the series."
     75652069
     73206E6F
     74207061
     7274206F
               .text
               .globl main
             main:

             .LFB971:

               .cfi_startproc
               .cfi_personality 0x3,__gxx_personality_v0
               .cfi_lsda 0x3,.LLSDA971
0000 55         pushq %rbp
               .cfi_def_cfa_offset 16
               .cfi_offset 6, -16
0001 4889E5     movq %rsp, %rbp
               .cfi_def_cfa_register 6
0004 4881ECF0   subq $240, %rsp
     000000

             .LBB2:

000b C78528FF   movl $50, -216(%rbp)
     FFFF3200
     0000

0015 C78518FF   movl $0, -232(%rbp)
     FFFF0000
     0000
001f 8B8528FF   movl -216(%rbp), %eax
     FFFF
0025 83E801     subl $1, %eax
0028 89851CFF   movl %eax, -228(%rbp)
     FFFF
002e 8B851CFF   movl -228(%rbp), %eax
     FFFF
0034 8B9518FF   movl -232(%rbp), %edx
     FFFF
003a 01D0       addl %edx, %eax
003c 89C2       movl %eax, %edx
003e C1EA1F     shrl $31, %edx
0041 01D0       addl %edx, %eax
0043 D1F8       sarl %eax
0045 898520FF   movl %eax, -224(%rbp)
     FFFF

004b C78530FF   movl $0, -208(%rbp)
     FFFF0000
     0000

0055 C78534FF   movl $1, -204(%rbp)
     FFFF0100
     0000

005f C78524FF   movl $1, -220(%rbp)
     FFFF0100
     0000

0069 EB65       jmp .L2

             .L3:

006b 8B8524FF   movl -220(%rbp), %eax
     FFFF
0071 8D4801     leal 1(%rax), %ecx
0074 8B8524FF   movl -220(%rbp), %eax
     FFFF
007a 83E801     subl $1, %eax
007d 4898       cltq
007f 8B948530   movl -208(%rbp,%rax,4), %edx
     FFFFFF
0086 8B8524FF   movl -220(%rbp), %eax
     FFFF
008c 4898       cltq
008e 8B848530   movl -208(%rbp,%rax,4), %eax
     FFFFFF
0095 01C2       addl %eax, %edx
0097 4863C1     movslq %ecx, %rax
009a 89948530   movl %edx, -208(%rbp,%rax,4)
     FFFFFF

00a1 838524FF   addl $1, -220(%rbp)
     FFFF01

00a8 8B8524FF   movl -220(%rbp), %eax
     FFFF
00ae 4898       cltq
00b0 8B848530   movl -208(%rbp,%rax,4), %eax
     FFFFFF
00b7 89C6       movl %eax, %esi
00b9 BF000000   movl $_ZSt4cout, %edi
     00

             .LEHB0:

00be E8000000   call _ZNSolsEi
     00
00c3 BE000000   movl $.LC0, %esi
     00
00c8 4889C7     movq %rax, %rdi
00cb E8000000   call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
     00

             .L2:

00d0 8B8524FF   movl -220(%rbp), %eax
     FFFF
00d6 4898       cltq
00d8 8B948530   movl -208(%rbp,%rax,4), %edx
     FFFFFF
00df 8B8524FF   movl -220(%rbp), %eax
     FFFF
00e5 83E801     subl $1, %eax
00e8 4898       cltq
00ea 8B848530   movl -208(%rbp,%rax,4), %eax
     FFFFFF
00f1 01D0       addl %edx, %eax
00f3 3B8528FF   cmpl -216(%rbp), %eax
     FFFF
00f9 0F8C6CFF   jl .L3
     FFFF

00ff C7852CFF   movl $8, -212(%rbp)
     FFFF0800
     0000

0109 E9A90000   jmp .L4
     00

             .L7:

010e 8B8520FF   movl -224(%rbp), %eax
     FFFF
0114 4898       cltq
0116 8B848530   movl -208(%rbp,%rax,4), %eax
     FFFFFF
011d 3B852CFF   cmpl -212(%rbp), %eax
     FFFF
0123 7E2E       jle .L5

0125 8B8520FF   movl -224(%rbp), %eax
     FFFF
012b 83E801     subl $1, %eax
012e 89851CFF   movl %eax, -228(%rbp)
     FFFF

0134 8B851CFF   movl -228(%rbp), %eax
     FFFF
013a 8B9518FF   movl -232(%rbp), %edx
     FFFF
0140 01D0       addl %edx, %eax
0142 89C2       movl %eax, %edx
0144 C1EA1F     shrl $31, %edx
0147 01D0       addl %edx, %eax
0149 D1F8       sarl %eax
014b 898520FF   movl %eax, -224(%rbp)
     FFFF
0151 EB64       jmp .L4

             .L5:

0153 8B8520FF   movl -224(%rbp), %eax
     FFFF
0159 4898       cltq
015b 8B848530   movl -208(%rbp,%rax,4), %eax
     FFFFFF
0162 3B852CFF   cmpl -212(%rbp), %eax
     FFFF
0168 7D2E       jge .L6

016a 8B8520FF   movl -224(%rbp), %eax
     FFFF
0170 83C001     addl $1, %eax
0173 898518FF   movl %eax, -232(%rbp)
     FFFF

0179 8B851CFF   movl -228(%rbp), %eax
     FFFF
017f 8B9518FF   movl -232(%rbp), %edx
     FFFF
0185 01D0       addl %edx, %eax
0187 89C2       movl %eax, %edx
0189 C1EA1F     shrl $31, %edx
018c 01D0       addl %edx, %eax
018e D1F8       sarl %eax
0190 898520FF   movl %eax, -224(%rbp)
     FFFF
0196 EB1F       jmp .L4

             .L6:

0198 BE000000   movl $.LC1, %esi
     00
019d BF000000   movl $_ZSt4cout, %edi
     00
01a2 E8000000   call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
     00
01a7 8B9520FF   movl -224(%rbp), %edx
     FFFF
01ad 89D6       movl %edx, %esi
01af 4889C7     movq %rax, %rdi
01b2 E8000000   call _ZNSolsEi
     00

             .L4:

01b7 8B8518FF   movl -232(%rbp), %eax
     FFFF
01bd 3B851CFF   cmpl -228(%rbp), %eax
     FFFF
01c3 0F8E45FF   jle .L7
     FFFF

01c9 BE000000   movl $.LC2, %esi
     00
01ce BF000000   movl $_ZSt4cout, %edi
     00
01d3 E8000000   call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
     00

             .LEHE0:

             .LBE2:

01d8 B8000000   movl $0, %eax
     00
01dd EB08       jmp .L11

             .L10:

01df 4889C7     movq %rax, %rdi

             .LEHB1:

01e2 E8000000   call _Unwind_Resume
     00

             .LEHE1:

             .L11:

01e7 C9         leave
               .cfi_def_cfa 7, 8
01e8 C3         ret
               .cfi_endproc

             .LFE971:

               .globl __gxx_personality_v0
               .section .gcc_except_table,"a",@progbits

             .LLSDA971:

0000 FF         .byte 0xff
0001 FF         .byte 0xff
0002 01         .byte 0x1
0003 0C         .uleb128 .LLSDACSE971-.LLSDACSB971

             .LLSDACSB971:

0004 BE01       .uleb128 .LEHB0-.LFB971
0006 9A02       .uleb128 .LEHE0-.LEHB0
0008 DF03       .uleb128 .L10-.LFB971
000a 00         .uleb128 0
000b E203       .uleb128 .LEHB1-.LFB971
000d 05         .uleb128 .LEHE1-.LEHB1
000e 00         .uleb128 0
000f 00         .uleb128 0

             .LLSDACSE971:

               .text
             _Z41__static_initialization_and_destruction_0ii:

             .LFB975:
0206 BF000000   movl $_ZStL8__ioinit, %edi
     00
020b E8000000   call _ZNSt8ios_base4InitC1Ev
     00
0210 BA000000   movl $__dso_handle, %edx
     00
0215 BE000000   movl $_ZStL8__ioinit, %esi
     00
021a BF000000   movl $_ZNSt8ios_base4InitD1Ev, %edi
     00
021f E8000000   call __cxa_atexit
     00

               .cfi_startproc
01e9 55         pushq %rbp
               .cfi_def_cfa_offset 16
               .cfi_offset 6, -16
01ea 4889E5     movq %rsp, %rbp
               .cfi_def_cfa_register 6
01ed 4883EC10   subq $16, %rsp
01f1 897DFC     movl %edi, -4(%rbp)
01f4 8975F8     movl %esi, -8(%rbp)
01f7 837DFC01   cmpl $1, -4(%rbp)
01fb 7527       jne .L12
01fd 817DF8FF   cmpl $65535, -8(%rbp)
     FF0000
0204 751E       jne .L12

             .L12:

0224 C9         leave
               .cfi_def_cfa 7, 8
0225 C3         ret
               .cfi_endproc

             .LFE975:

             _GLOBAL__sub_I_main:

             .LFB976:

               .cfi_startproc
0226 55         pushq %rbp
               .cfi_def_cfa_offset 16
               .cfi_offset 6, -16
0227 4889E5     movq %rsp, %rbp
               .cfi_def_cfa_register 6
022a BEFFFF00   movl $65535, %esi
     00
022f BF010000   movl $1, %edi
     00
0234 E8B0FFFF   call _Z41__static_initialization_and_destruction_0ii
     FF
0239 5D         popq %rbp
               .cfi_def_cfa 7, 8
023a C3         ret
               .cfi_endproc

             .LFE976:

               .section .init_array,"aw"
               .align 8
0000 00000000   .quad _GLOBAL__sub_I_main
     00000000
               .text

             .Letext0:

© ynh - Powered by Node.js

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote