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

Write an Assembly program with Pep/8 that reads an integer and then stores all F

ID: 3568028 • Letter: W

Question

Write an Assembly program with Pep/8 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 comments most if not all your statements. You can use C++ code for commenting your statements.

Explanation / Answer

Assembly language code:

  

            .Ltext0:

                        .local      _ZStL8__ioinit

                        .comm _ZStL8__ioinit,1,1

                        .section    .rodata

                        .align 8

                  .LC0:

0000 456E7465           .string     "Enter the limit of Fibonacci series: "

     72207468

     65206C69

     6D697420

     6F662046

                  .LC1:

0026 69207661           .string     "i value is: "

     6C756520

     69733A20

     00

                  .LC2:

0033 54686520           .string     "The Fibonacci series is: "

     4669626F

     6E616363

     69207365

     72696573

                  .LC3:

004e 6E756D73           .string     "nums["

     5B00

                  .LC4:

0054 5D203D20           .string     "] = "

     00

                  .LC5:

0059 0A00               .string     " "

                  .LC6:

005b 0A456E74           .string     " Enter the value to find : "

     65722074

     68652076

     616C7565

     20746F20

                  .LC7:

0077 0A56616C           .string     " Value "

     75652000

                  .LC8:

007f 20666F75           .string     " found at index "

     6E642061

     7420696E

     64657820

     00

                  .LC9:

0090 20697320           .string     " is not part of the series. "

     6E6F7420

     70617274

     206F6620

     74686520

                        .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 53                 pushq %rbx

0005 4881ECF8           subq $248, %rsp

     000000

                        .cfi_offset 3, -24

                  .LBB2:

000c BE000000           movl $.LC0, %esi

     00

0011 BF000000           movl $_ZSt4cout, %edi

     00

                  .LEHB0:

0016 E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

001b 488D8504           leaq -252(%rbp), %rax

     FFFFFF

0022 4889C6             movq %rax, %rsi

0025 BF000000           movl $_ZSt3cin, %edi

     00

002a E8000000           call _ZNSirsERi

     00

002f C7850CFF           movl $0, -244(%rbp)

     FFFF0000

     0000

0039 C78520FF           movl $0, -224(%rbp)

     FFFF0000

     0000

0043 EB5A               jmp   .L2

                  .L4:

0045 83850CFF           addl $1, -244(%rbp)

     FFFF01

004c 83BD0CFF           cmpl $1, -244(%rbp)

     FFFF01

0053 7515               jne   .L3

0055 8B850CFF           movl -244(%rbp), %eax

     FFFF

005b 4898               cltq

005d C7848520           movl $1, -224(%rbp,%rax,4)

     FFFFFF01

     000000

0068 EB35               jmp   .L2

                  .L3:

006a 8B850CFF           movl -244(%rbp), %eax

     FFFF

0070 83E801             subl $1, %eax

0073 4898               cltq

0075 8B948520           movl -224(%rbp,%rax,4), %edx

     FFFFFF

007c 8B850CFF           movl -244(%rbp), %eax

     FFFF

0082 83E802             subl $2, %eax

0085 4898               cltq

0087 8B848520           movl -224(%rbp,%rax,4), %eax

     FFFFFF

008e 01C2               addl %eax, %edx

0090 8B850CFF           movl -244(%rbp), %eax

     FFFF

0096 4898               cltq

0098 89948520           movl %edx, -224(%rbp,%rax,4)

     FFFFFF

                  .L2:

009f 8B850CFF           movl -244(%rbp), %eax

     FFFF

00a5 4898               cltq

00a7 8B948520           movl -224(%rbp,%rax,4), %edx

     FFFFFF

00ae 8B8504FF           movl -252(%rbp), %eax

     FFFF

00b4 39C2               cmpl %eax, %edx

00b6 7E8D               jle   .L4

00b8 BE000000           movl $.LC1, %esi

     00

00bd BF000000           movl $_ZSt4cout, %edi

     00

00c2 E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

00c7 8B950CFF           movl -244(%rbp), %edx

     FFFF

00cd 89D6               movl %edx, %esi

00cf 4889C7             movq %rax, %rdi

00d2 E8000000           call _ZNSolsEi

     00

00d7 BE000000           movl      $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi

     00

00dc 4889C7             movq %rax, %rdi

00df E8000000           call _ZNSolsEPFRSoS_E

     00

00e4 BE000000           movl $.LC2, %esi

     00

00e9 BF000000           movl $_ZSt4cout, %edi

     00

00ee E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

                  .LBB3:

00f3 C78510FF           movl $0, -240(%rbp)

     FFFF0000

     0000

00fd EB5B               jmp   .L5

                  .L6:

0153 838510FF           addl $1, -240(%rbp)

     FFFF01

00ff 8B8510FF           movl -240(%rbp), %eax

     FFFF

0105 4898               cltq

0107 8B9C8520           movl -224(%rbp,%rax,4), %ebx

     FFFFFF

010e BE000000           movl $.LC3, %esi

     00

0113 BF000000           movl $_ZSt4cout, %edi

     00

0118 E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

011d 8B9510FF           movl -240(%rbp), %edx

     FFFF

0123 89D6               movl %edx, %esi

0125 4889C7             movq %rax, %rdi

0128 E8000000           call _ZNSolsEi

     00

012d BE000000           movl $.LC4, %esi

     00

0132 4889C7             movq %rax, %rdi

0135 E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

013a 89DE              movl %ebx, %esi

013c 4889C7             movq %rax, %rdi

013f E8000000           call _ZNSolsEi

     00

0144 BE000000           movl $.LC5, %esi

     00

0149 BF000000           movl $_ZSt4cout, %edi

     00

014e E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

                  .L5:

015a 8B8510FF           movl -240(%rbp), %eax

     FFFF

0160 3B850CFF           cmpl -244(%rbp), %eax

     FFFF

0166 7C97               jl    .L6

                  .LBE3:

0168 BE000000           movl $.LC6, %esi

     00

016d BF000000           movl $_ZSt4cout, %edi

     00

0172 E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

0177 488D8508           leaq -248(%rbp), %rax

     FFFFFF

017e 4889C6             movq %rax, %rsi

0181 BF000000           movl $_ZSt3cin, %edi

     00

0186 E8000000           call _ZNSirsERi

     00

018b C78514FF           movl $0, -236(%rbp)

     FFFF0000

     0000

0195 8B850CFF           movl -244(%rbp), %eax

     FFFF

019b 83E801             subl $1, %eax

019e 898518FF           movl %eax, -232(%rbp)

     FFFF

01a4 8B8518FF           movl -232(%rbp), %eax

     FFFF

01aa 8B9514FF           movl -236(%rbp), %edx

     FFFF

01b0 01D0               addl %edx, %eax

01b2 89C2               movl %eax, %edx

01b4 C1EA1F             shrl $31, %edx

01b7 01D0               addl %edx, %eax

01b9 D1F8               sarl %eax

01bb 89851CFF           movl %eax, -228(%rbp)

     FFFF

01c1 E9240100           jmp   .L7

     00

                  .L12:

01c6 8B851CFF           movl -228(%rbp), %eax

     FFFF

01cc 4898               cltq

01ce 8B948520           movl -224(%rbp,%rax,4), %edx

     FFFFFF

01d5 8B8508FF           movl -248(%rbp), %eax

     FFFF

01db 39C2               cmpl %eax, %edx

01dd 7E31               jle   .L8

01df 8B851CFF           movl -228(%rbp), %eax

     FFFF

01e5 83E801             subl $1, %eax

01e8 898518FF           movl %eax, -232(%rbp)

     FFFF

01ee 8B8518FF           movl -232(%rbp), %eax

     FFFF

01f4 8B9514FF           movl -236(%rbp), %edx

     FFFF

01fa 01D0               addl %edx, %eax

01fc 89C2               movl %eax, %edx

01fe C1EA1F             shrl $31, %edx

0201 01D0               addl %edx, %eax

0203 D1F8               sarl %eax

0205 89851CFF           movl %eax, -228(%rbp)

     FFFF

020b E9DA0000           jmp   .L7

     00

                  .L8:

0210 8B851CFF           movl -228(%rbp), %eax

     FFFF

0216 4898               cltq

0218 8B948520           movl -224(%rbp,%rax,4), %edx

     FFFFFF

021f 8B8508FF           movl -248(%rbp), %eax

     FFFF

0225 39C2               cmpl %eax, %edx

0227 7D31               jge   .L9

0229 8B851CFF           movl -228(%rbp), %eax

     FFFF

022f 83C001             addl $1, %eax

0232 898514FF           movl %eax, -236(%rbp)

     FFFF

0238 8B8518FF           movl -232(%rbp), %eax

     FFFF

023e 8B9514FF           movl -236(%rbp), %edx

     FFFF

0244 01D0               addl %edx, %eax

0246 89C2               movl %eax, %edx

0248 C1EA1F             shrl $31, %edx

024b 01D0               addl %edx, %eax

024d D1F8               sarl %eax

024f 89851CFF           movl %eax, -228(%rbp)

     FFFF

0255 E9900000           jmp   .L7

     00

                  .L9:

025a 8B851CFF           movl -228(%rbp), %eax

     FFFF

0260 4898               cltq

0262 8B948520           movl -224(%rbp,%rax,4), %edx

     FFFFFF

0269 8B8508FF           movl -248(%rbp), %eax

     FFFF

026f 39C2               cmpl %eax, %edx

0271 754B               jne   .L10

0273 8B9D08FF           movl -248(%rbp), %ebx

     FFFF

0279 BE000000           movl $.LC7, %esi

     00

027e BF000000           movl $_ZSt4cout, %edi

   00

0283 E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

0288 89DE               movl %ebx, %esi

028a 4889C7             movq %rax, %rdi

028d E8000000           call _ZNSolsEi

     00

0292 BE000000           movl $.LC8, %esi

     00

0297 4889C7             movq %rax, %rdi

029a E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

029f 8B951CFF           movl -228(%rbp), %edx

     FFFF

02a5 89D6               movl %edx, %esi

02a7 4889C7             movq %rax, %rdi

02aa E8000000           call _ZNSolsEi

     00

02af BE000000           movl      $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi

     00

02b4 4889C7             movq %rax, %rdi

02b7 E8000000           call _ZNSolsEPFRSoS_E

     00

02bc EB3E               jmp   .L11

                  .L10:

02be 8B9D08FF           movl -248(%rbp), %ebx

     FFFF

02c4 BE000000           movl $.LC7, %esi

     00

02c9 BF000000           movl $_ZSt4cout, %edi

     00

02ce E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

02d3 89DE               movl %ebx, %esi

02d5 4889C7             movq %rax, %rdi

02d8 E8000000           call _ZNSolsEi

     00

02dd BE000000           movl $.LC9, %esi

     00

02e2 4889C7             movq %rax, %rdi

02e5 E8000000           call      _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

     00

                  .LEHE0:

                  .L7:

02ea 8B8514FF           movl -236(%rbp), %eax

     FFFF

02f0 3B8518FF           cmpl -232(%rbp), %eax

     FFFF

02f6 0F8ECAFE           jle   .L12

     FFFF

                  .L11:

02fc B8000000           movl $0, %eax

     00

0301 EB08               jmp   .L16

                  .L15:

0303 4889C7             movq %rax, %rdi

                  .LEHB1:

0306 E8000000           call _Unwind_Resume

     00

                  .LEHE1:

                  .L16:

                  .LBE2:

030b 4881C4F8           addq $248, %rsp

     000000

0312 5B                 popq %rbx

0313 5D                 popq %rbp

                        .cfi_def_cfa 7, 8

0314 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 0B                 .uleb128 .LLSDACSE971-.LLSDACSB971

                  .LLSDACSB971:

0004 16                 .uleb128 .LEHB0-.LFB971

0005 D405               .uleb128 .LEHE0-.LEHB0

0007 8306               .uleb128 .L15-.LFB971

0009 00                 .uleb128 0

000a 8606               .uleb128 .LEHB1-.LFB971

000c 05                 .uleb128 .LEHE1-.LEHB1

000d 00                 .uleb128 0

000e 00                 .uleb128 0

                  .LLSDACSE971:

                        .text

                  _Z41__static_initialization_and_destruction_0ii:

                  .LFB980:

0332 BF000000           movl $_ZStL8__ioinit, %edi

     00

0337 E8000000           call _ZNSt8ios_base4InitC1Ev

     00

033c BA000000           movl $__dso_handle, %edx

     00

0341 BE000000           movl $_ZStL8__ioinit, %esi

     00

0346 BF000000           movl $_ZNSt8ios_base4InitD1Ev, %edi

     00

034b E8000000           call __cxa_atexit

     00

                        .cfi_startproc

0315 55                 pushq %rbp

                        .cfi_def_cfa_offset 16

                        .cfi_offset 6, -16

0316 4889E5             movq %rsp, %rbp

                        .cfi_def_cfa_register 6

0319 4883EC10           subq $16, %rsp

031d 897DFC             movl %edi, -4(%rbp)

0320 8975F8             movl %esi, -8(%rbp)

0323 837DFC01           cmpl $1, -4(%rbp)

0327 7527               jne   .L17

0329 817DF8FF           cmpl $65535, -8(%rbp)

     FF0000

0330 751E               jne   .L17

                  .L17:

0350 C9                 leave

                        .cfi_def_cfa 7, 8

0351 C3                 ret

                        .cfi_endproc

                  .LFE980:

                  _GLOBAL__sub_I_main:

                  .LFB981:

                        .cfi_startproc

0352 55                 pushq %rbp

                        .cfi_def_cfa_offset 16

                      .cfi_offset 6, -16

0353 4889E5             movq %rsp, %rbp

                        .cfi_def_cfa_register 6

0356 BEFFFF00           movl $65535, %esi

     00

035b BF010000           movl $1, %edi

     00

0360 E8B0FFFF           call      _Z41__static_initialization_and_destruction_0ii

    FF

0365 5D                 popq %rbp

                        .cfi_def_cfa 7, 8

0366 C3                 ret

                        .cfi_endproc

                  .LFE981:

                        .section    .init_array,"aw"

                        .align 8

0000 00000000           .quad _GLOBAL__sub_I_main

     00000000

                        .text

                  .Letext0:

Program Code in C++:

// FebnociiSeries.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <iostream>

using namespace std;

int main()

{

    int nums[50]; //populate array with Fibonacci numbers up to the limit

    int size;

    cout<<"Enter the limit of Fibonacci series: ";

    cin>>size;

    int i=0;

     nums[0] = 0;

   

    while(nums[i]<=size)

     {

          i++;

          if ( i == 1 )

              nums[i] = 1;

          else

              nums[i] = nums[i -1] + nums[i -2];       

        

     }

     cout<<"i value is: "<<i<<endl;

     int value;

     cout<<"The Fibonacci series is: ";

     for(int j=0;j<i;j++)

     {

          cout<< "nums[" << j << "] = " << nums[j];

          cout<<" ";

     }

     cout<<" Enter the value to find : " ;

     cin>>value;

     int first = 0, last = i - 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 if(value==nums[mid])

          {

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

              break;

          }

          else

          {

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

          }

     }

   

     system("pause");

     return 0;

}

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